DateTime does not exist in the current context

I have the following class

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;
        } 
    }
}

When I debug and I use the "Add Clock" in DateTime.Now.Date, I get

"DateTime does not exist in the current context."

And the condition is never fulfilled, even if the dates match.

Why am I turning on System?

+4
source share
2 answers

Here are a few things I've seen:

  • You may need to add mscorlib.dll as a link in your project.
  • You cannot compare with DateTime(newDate) and int(DateTime.Now.Day) with ==, You may have to use newDate == DateTime.Now.
  • After your returncommands, you are missing a half-colony ( ;).
  • System.Globalization CultureInfo.
+5

, , "DateTime", "Datetime" - . "DateTime" ( ).

0

Source: https://habr.com/ru/post/1525042/


All Articles