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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 26, 2014, 6:19 AM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 26, 2014, 6:32 AM EDT
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.
Posted Apr 26, 2014, 12:34 PM EDT