Can someone explain this one too?
Getting a default value with Nullable Types:
int? n1=null; int n2=3;
(n1 ?? 10) will return the value 10.
int product= (n1 ?? 10) * n2; Now product will hold 30 since (n1??10) will return 10.
now,what does the statement " (n1 ?? 10) " means and why doe开发者_JAVA百科s it return the value '10'
From MSDN:
The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.
I think any extra comment is not required
I don't usually program in C#, but ?? is the null-coalescing operator as described in MSDN's "?? Operator (C# Reference)".
n1 ?? 10
Basically says "If n1 is null, then change it to the default value of 10."
精彩评论