可能重复:
Nullable type is not a nullable type?为什么的GetType()返回DateTime类型为可空<DateTime>
在以下代码:
DateTime? dt = DateTime.Now;
MessageBox.Show(dt.GetType().ToString());
消息框中显示“系统.DateTime“,而不是Nullable<DateTime>
。下面的方式也返回false(因为对GetType是错误的):
if (dt.GetType().IsAssignableFrom(typeof(DateTime?)))
...
(顺便说一句,使用DateTime?
或Nullable<DateTime>
不会有所作为) 在监视窗口中,你有“类型”一栏多数民众赞成显示正确的类型(System.DateTime?)。
在我的代码中,我将dt引用为object
,所以我需要正确地使用基础类型。我怎样才能做到这一点?
重复http://stackoverflow.com/questions/785358/nullable-type-is-not-a-nullable-type的“怪异”的行为似乎有一个很好的答案 – Chris 2011-01-21 13:41:00
请参阅http://msdn.microsoft。com/en-us/library/ms366789(v = VS.100).aspx的一些信息,但不是解决方案 – 2011-01-21 13:46:36