Point Deep

Mundeep's Tech Blog

Posts Tagged ‘csharp’

c# if else alternative syntax using ? : operator

Posted by mundeep on July 15, 2011

One of the c# operators i tend to use a lot is the ?: operator which is essentially an alternative syntax to an if else statement. Unfortunately i often forget the order of the statements so am adding this quick post as a note for myself to easily remember 🙂

Essentially:

condition ? first_expression : second_expression;

Is equivalent to:

if (condition) {
 first_expression;
}
else {
 second_expression;
}

References:

Advertisements

Posted in .NET | Tagged: , , | 2 Comments »