1. Use Cases
2. ReferenceArticleAnd examplesCodeDownload
1. Use Cases
Msdn:It returns the left-hand operand if it is not null; otherwise it returns the right operand. if the left value is not blank, the left value is returned. Otherwise, the right value is returned. The following is a test example:
class nullcoalesce
{< br> static int ? getnullableint ()
{< br> return null ;< BR >}
static string getstringvalue ()
{< br> return null ;
}
static void main ()
{< br> /// ?? Operator example.
int ? x = null ;
//Y = x, unless X is null, in which case y =-1.
IntY=X?? -1;
// Assign I to return value of method, unless
// Return Value is null, in which case assign
// Default Value of int to I.
Int I = Getnullableint () ?? Default ( Int );
String S = Getstringvalue ();
// ?? Also works with reference types.
// Display contents of S, unless s is null,
// In which case display "unspecified ".
Console. writeline (S ?? " Unspecified " );
}
}
2. Download reference articles and sample code
References:
Http://msdn.microsoft.com/en-us/library/ms173224.aspx