According to MSDN:
The ?? operator is called the null-coalescing operator and is used to
define a default value for nullable value types or reference types.
But when I run the code below:
Guid test;
Guid otherGuid = test ?? Guid.NewGuid();
I get the error:
Operator ‘??’ cannot be applied to operands of type ‘System.Guid’ and
‘System.Guid’
I thought Guid was a reference type. Is that not the case? Could someone explain to my why this does not work?
Guidis not a reference type, its a value type, you can’t assign it null and that is why you can’t check it with??Following line will give you error.
You may use Nullable
Or short form