Does anyone know how to deal with this error?
cannot convert from 'System.Guid?' to 'System.Guid'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See MSDN.
In that case, merely use
myNullableVariable.Value(if you’re sure it has a value), or(myNullableVariable.HasValue)?myNullableVariable.Value:somedefaulthereif 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 aNullable<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 theNullablemanually. The third way i listed is the most succinct (and best?) way to do it, to that would probably be best in most cases.