不能从转换'的System.Guid?“到“的System.Guid” [英] cannot convert from 'System.Guid?' to 'System.Guid'

查看:1356
本文介绍了不能从转换'的System.Guid?“到“的System.Guid”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道怎么处理这个问题?

 不能从转换'的System.Guid?到的System.Guid
 

解决方案

请参阅 MSDN

在这种情况下,仅仅使用 myNullableVariable.Value (如果你确定它有一个值),或(myNullableVariable.HasValue)? myNullableVariable.Value:somedefaulthere 如果你不是

你也可以使用 GetValueOrDefault(),如果一个不小心,如果默认为一个特定的值时,可空还真是空。

做最后的方法是这样的: myNullableVariable.Value?默认值

见,技术上的MyType 变量是一个可空< MyType的> 在幕后。有两者之间没有隐式或显式转换,所以你需要做的是提取值了可空手动的。第三种方式我上市是最简洁的(和最好的吗?)的方式来做到这一点,以至于很可能是最好在大多数情况下。

Does anyone know how to deal with this error?

cannot convert from 'System.Guid?' to 'System.Guid'

解决方案

See MSDN.

In that case, merely use myNullableVariable.Value (if you're sure it has a value), or (myNullableVariable.HasValue)?myNullableVariable.Value:somedefaulthere if you're not.

One can also use GetValueOrDefault() if one doesn't care if the default is a specific value when the nullable really is null.

The last way to do it is this: myNullableVariable.Value ?? defaultvalue.

See, technically a MyType? variable is a Nullable<MyType> under the covers. There are no implicit or explicit casts between the two, so what you need to do is extract the value out of the Nullable manually. The third way i listed is the most succinct (and best?) way to do it, to that would probably be best in most cases.

这篇关于不能从转换'的System.Guid?“到“的System.Guid”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆