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)

Thursday, February 28, 2008

C# Operator ?

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

code with operator 'if'

        string getName(string name)
{
if (name == null)
return "default";
else
return name;
}


code with operator '?'

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

Additional Links:

?: Operator (C# Reference)