DateTime在当前上下文中不存在

Hél*_*ves 5 .net c#

我有以下课程

using System;
using System.Globalization;

namespace GenericSomething
{
    public class Specific : Generic
    {
        public override bool DoSomething(string date)
        {
            DateTime newDate = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture);
            if (newDate.Date == DateTime.Now.Date)
                return true;
            else
                return false;
        } 
    }
}
Run Code Online (Sandbox Code Playgroud)

当我正在调试并在DateTime.Now.Date上使用"添加监视"时,我得到了

"当前上下文中不存在DateTime."

即使日期相同,也永远不会满足条件.

为什么这是我包括系统?

Son*_*nül 5

这里有一些我看到的东西;

  • 您可能需要在项目中添加mscorlib.dll作为参考.
  • 您无法与DateTime(newDate)和int(DateTime.Now.Day)与==运算符进行比较.您可能需要使用newDate == DateTime.Now.
  • 您;的return陈述后缺少分号().
  • 您需要System.Globalization为使用CultureInfo类添加命名空间.