C#不能隐式转换类型'字符串'到' System.DateTime'

时间:2015-11-07 00:41:13

标签: c#

DateTime Time = DateTime.Now;
string format = "ddd";
Console.WriteLine(Time.ToString(format));
if (Time = "Mon; Tue; Wed; Thu; Fri;") 

{
    Console.WriteLine("It is a week day");
}

else
{
    Console.WriteLine("it is a weekend");
}

我试图让这段代码检查日期并根据当天显示回复。很抱歉,如果这是一个简单的问题,但我不熟悉编码,我无法在任何地方找到解决方案

2 个答案:

答案 0 :(得分:3)

你可以这样做。

bool isWeekDay == DateTime.Today.DayOfWeek > DayOfWeek.Sunday 
    && DateTime.Today.DayOfWeek < DayOfWeek.Saturday;

if (isWeekDay) {
    Console.WriteLine("It is a week day");
}
else {
    Console.WriteLine("it is a weekend");
}

答案 1 :(得分:-3)

DateTime Time = DateTime.Now;
string format = "ddd";
Console.WriteLine(Time.ToString(format));
string day = Time.ToString(format);
if (day = "Mon; Tue; Wed; Thu; Fri;") 
{
    Console.WriteLine("It is a week day");
}
else
{
    Console.WriteLine("it is a weekend");
}