using System;
class Program
{
static void Main(string[] args)
{
int n1, n2;
n1 = 10;
n2 = 20;
int max = (n1 > n2) ? n1 : n2;
Console.WriteLine(max);//20
int min = (n1 < n2) ? n1 : n2;
Console.WriteLine(min);//10
Console.ReadKey();
}
}
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Apr 26, 2014, 4:34 PM
Abhay ShankerPosted Apr 26, 2014, 10:32 AM
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.
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.
VulpesPosted Apr 26, 2014, 10:19 AM