将项目更新到 Framework 3.5

发布于 2024-09-26 17:37:34 字数 384 浏览 3 评论 0原文

您好,我有一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

⒈起吃苦の倖褔 2024-10-03 17:37:34

听起来“theGuid”应该被定义为:

Guid? theGuid;

现在,由于某种原因,它在定义中没有使用 Nullable ,而是定义为:

Guid theGuid;

It sounds like "theGuid" should have been defined as:

Guid? theGuid;

And now, for some reason, it isn't using Nullable<T> in its definition, and is rather defined as:

Guid theGuid;
诺曦 2024-10-03 17:37:34

在 3.5 中,可空类型仍然是可能的。

您确定 theGuidGuid? 类型而不仅仅是 Guid 吗?

Nullable types are still possible in 3.5.

Are you sure theGuid is a Guid? type and not just Guid?

神妖 2024-10-03 17:37:34

HasValueValue可空结构。

因此,如果 theGuid 被声明为 nullable<,您的代码应该可以工作/a> Guid

Guid? theGuid = //...
Guid id;

if (theGuid.HasValue)
{
    id = theGuid.Value;
}

HasValue and Value are properties of the Nullable<T> struct.

So you code should work if theGuid was declared as nullable Guid:

Guid? theGuid = //...
Guid id;

if (theGuid.HasValue)
{
    id = theGuid.Value;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文