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 i;
int j = 1;
int []ar = {21, 22, 13, 4};
switch (ar[j])
{
case 1:
i++;
break;
case 2:
i += 2;
j = 3;
continue;
case 3:
i %= 2;
j = 4;
continue;
default:
–i;
}
Console.WriteLine(i);
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int i;
int j = 1;
int []ar = {21, 22, 13, 4};
switch (ar[j])
{
case 1:
i++;
break;
case 2:
i += 2;
j = 3;
continue;
case 3:
i %= 2;
j = 4;
continue;
default:
–i;
}
Console.WriteLine(i);
Console.ReadLine();
}
a) 23
b) 15
c) Compile time error
d) 12

Answer: c
Explanation: Continue cannot be used as a part of switch statement.

Join The Discussion