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)
{
int const p = 0;
switch (3 * 5 / 6)
{
case p:
Console.WriteLine(“A”);
break;
case p * 1:
Console.WriteLine(“B”);
break;
case p – 2:
Console.WriteLine(“C”);
break;
default:
Console.WriteLine(“D”);
}
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int const p = 0;
switch (3 * 5 / 6)
{
case p:
Console.WriteLine(“A”);
break;
case p * 1:
Console.WriteLine(“B”);
break;
case p – 2:
Console.WriteLine(“C”);
break;
default:
Console.WriteLine(“D”);
}
}
a) A
b) B
c) C
d) Compile time error

Answer: d
Explanation: In case expression we don’t have constant variable.

Join The Discussion