7.3: Ternary Expressions
File Location
Ternary Expressions
class Program
{
static void Main(string[] args)
{
int number = 10;
//If Else Statement
if (number == 7)
Console.WriteLine("The number is 7.");
else
Console.WriteLine("The number is not 7.");
//Ternary Expression:
//1 //2 //3 //4 //5
string response = ((number == 7) ? "The number is 7." : "The number is not 7.");
Console.WriteLine(response);
}
}Discussion
Further Practice
Last updated