This C# program demonstrates how the conditional operator is used. The conditional evaluates to one of two values, depending on the value of a boolean value.
using System;
namespace XoaX {
class Program {
static void Main(string[] args) {
bool P = true;
int i = 5;
int j = 10;
Console.WriteLine("({0} ? {1} : {2}) = " + (P ? i : j), P, i, j);
P = false;
Console.WriteLine("({0} ? {1} : {2}) = " + (P ? i : j), P, i, j);
}
}
}
(True ? 5 : 10) = 5 (False ? 5 : 10) = 10 Press any key to continue . . .
© 20072025 XoaX.net LLC. All rights reserved.