DateTime在当前上下文中不存在

编程入门 行业动态 更新时间:2024-10-26 08:24:58
本文介绍了DateTime在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下课程

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

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

When I'm debugging and i use "Add watch" on DateTime.Now.Date, i get

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

"DateTime does not exist in the current context."

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

And the condition is never satisfied even if the dates are the same.

为什么我要包含系统?

推荐答案

以下是我看到的一些内容;

Here a few things I saw;

  • 您可能需要在项目中添加 mscorlib.dll 作为参考.
  • 您不能与 DateTime ( newDate )和 int ( DateTime.Now.Day )进行比较使用 == 运算符.您可能需要改用 newDate == DateTime.Now .
  • return 语句后,您缺少分号(; ).
  • 您需要添加 System.Globalization 名称空间,用于使用 CultureInfo 类.
  • You might be need to add mscorlib.dll as a reference in your project.
  • You can't compare with DateTime (newDate) and int (DateTime.Now.Day) with == operator. You might need to use newDate == DateTime.Now instead.
  • You are missing semi-colon (;) after your return statements.
  • You need to add System.Globalization namespace for using CultureInfo class.

更多推荐

DateTime在当前上下文中不存在

本文发布于:2023-11-09 15:12:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   中不   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!