Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
switch (5)
{
case 5.0f:
Console.WriteLine(“harsh”);
break;
case 5:
Console.WriteLine(“amish”);
break;
case 5.0L:
Console.WriteLine(“ANKIT”);
break;
default:
Console.WriteLine(“ashish”);
}
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
switch (5)
{
case 5.0f:
Console.WriteLine(“harsh”);
break;
case 5:
Console.WriteLine(“amish”);
break;
case 5.0L:
Console.WriteLine(“ANKIT”);
break;
default:
Console.WriteLine(“ashish”);
}
Console.ReadLine();
}
a) amish
b) ANKIT
c) harsh
d) Compile time error

Answer: d
Explanation: Only integral values are allowed for case expression.
5.0f = (int)5.0f.
5.0L = (int)5.0L.

Join The Discussion