c# if function code example
Example 1: c# else if
string emotions;
emotions = Console.ReadLine();
if (emotions == "happy")
{
Console.Write("You are happy");
}
else if (emotions == "sad")
{
Console.Write("You are sad");
}
else if (emotions == "mad")
{
Console.Write("You are mad");
}
else
{
Console.Write("Unknown input");
}
Example 2: nested if statement example in c#
class Program{
static void Main(string[] args){
Console.WriteLine("Enter a any number between 1 to 10");
int num1 = Convert.ToInt16(Console.ReadLine());
if (num1 > 100){
Console.WriteLine("Wrong number, {0}", num1);
}else{
if (num1 == 9){
Console.WriteLine("Jackpot number, {0}", num1);
}else{
Console.WriteLine("Your number, {0}", num1);
}
}
}
}