Thursday, June 12, 2014

[ MSDN.Microsoft.com ] The Conditional Operator in CSharp and how it help in the if-else statement

The condition must evaluate to true or false. If condition is true, first_expression is evaluated and becomes the result. If condition is false, second_expression is evaluated and becomes the result. Only one of the two expressions is evaluated.

Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other.

You can express calculations that might otherwise require an if-else construction more concisely by using the conditional operator. For example, the following code uses first an if statement and then a conditional operator to classify an integer as positive or negative.

Check out this page for more details

?: Operator (C# Reference)

Post a Comment

Know us

Our Team

Tags

Video of the Day

Contact us

Name

Email *

Message *