hexlocation
hexlocation
CC#
Created by hexlocation on 1/31/2023 in #help
error CS0176: Member 'DateTime.Now' cannot be accessed with an instance reference; qualify it with a
Hi, i'm a beginner and i come from JavaScript and python. I'm having an issue with my CSharp code:
using System;
using System.Net; //required
using System.Net.Sockets; //required
namespace Server
{
public class print
{

public void errlog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] ERR: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
public void infolog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] INFO: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
}

class Server
{
private String hostip = "0.0.0.0";
private int hostport = 8713;
static void Main(string[] args){
print.errlog("Hello! This is an error!");
print.infolog("Hello! This is a debug log!");
}
}
}
using System;
using System.Net; //required
using System.Net.Sockets; //required
namespace Server
{
public class print
{

public void errlog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] ERR: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
public void infolog(String txt)
{
System.DateTime today = System.DateTime.Today;
Console.WriteLine("[{0}] INFO: {1}", today.Now.ToString("yyyy-MM-dd hh:mm:ss"), txt);
}
}

class Server
{
private String hostip = "0.0.0.0";
private int hostport = 8713;
static void Main(string[] args){
print.errlog("Hello! This is an error!");
print.infolog("Hello! This is a debug log!");
}
}
}
It just errors out: Member 'DateTime.Now' cannot be accessed with an instance reference; qualify it with a type name instead
8 replies