Friday, February 29, 2008

C# Operator ??

Instead of operator 'if ' and '?' sometimes we can use operator '??'

code with operator 'if'

image

code with operator '?'

string getName_with_operator_question(string name)
{
return (name == null) ? "default" : name;
}



code with operator '??'




string getName_with_operator_double_question(string name)
{
return name ?? "default";
}



Sample can be download:



Operaors ? and ?? sample



Additional Links:



?? Operator (C# Reference)

No comments: