将项目更新到 Framework 3.5
您好,我有一个在 3.5 之前的版本中创建的项目。从那时起,我运行向导将其升级到 3.5。完成此操作后,我构建了该项目,但出现错误。错误是 Guid 正在尝试访问属性 HasValue 和 Value:
if(theGuid.HasValue)
{
id = theGuid.Value
}
错误是“System.Guid”不包含“HasValue”的定义,并且没有扩展方法“HasValue”接受类型“System.Guid”的第一个参数' 可以找到(您是否缺少 using 指令或程序集引用?)
该错误与 Value 属性类似。
有人可以告诉我发生了什么事吗?它是从框架中取出的属性吗?如果是的话我可以用什么来代替它?
谢谢!
Hi I have a project that was created in a previous version to 3.5. I since then ran the wizard to upgrade it to 3.5. After I did this I built the project but it has an error. The error is that a Guid is trying to access the properties HasValue and Value:
if(theGuid.HasValue)
{
id = theGuid.Value
}
The errors are 'System.Guid' does not contain a definition for 'HasValue' and no extension method 'HasValue' accepting a first argument of type 'System.Guid' could be found (are you missing a using directive or an assembly reference?)
The error is similiar for the Value property.
Can someone please tell me what's going on? Is it a property that was taken out of the framework? If so what could I replace it with?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来“theGuid”应该被定义为:
现在,由于某种原因,它在定义中没有使用
Nullable
,而是定义为:It sounds like "theGuid" should have been defined as:
And now, for some reason, it isn't using
Nullable<T>
in its definition, and is rather defined as:在 3.5 中,可空类型仍然是可能的。
您确定
theGuid
是Guid?
类型而不仅仅是Guid
吗?Nullable types are still possible in 3.5.
Are you sure
theGuid
is aGuid?
type and not justGuid
?HasValue
和Value
是 可空因此,如果
theGuid
被声明为 nullable<,您的代码应该可以工作/a> Guid:HasValue
andValue
are properties of the Nullable<T> struct.So you code should work if
theGuid
was declared as nullable Guid: