Vidyalelo
C# Programming · all questions

Control Flow Statements in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

92

Questions

5/5

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 5;
    for (; Convert.ToBoolean(Convert.ToInt32(i)); Console.WriteLine(i--)) ;
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{  
    int a = 5;
    if (Convert.ToBoolean((.002f) -(0.1f)))
    Console.WriteLine("Sachin Tendulkar");
    else if (a == 5)
    Console.WriteLine("Rahul Dravid");
    else
    Console.WriteLine("Ms Dhoni");
    Console.ReadLine();
}

Select an option to see the answer and solution.

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();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    float i = 1.0f,  j = 0.05f;
    while (i  < 2.0f  &&  j  <= 2.0f)
    {
        Console.WriteLine(i++ - ++j);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i, j;
    for (i = 1, j = i; i <= 3 && j >= 0; i++, j--)
    {
        if (i == j)
            continue;
        else
            Console.WriteLine(j);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

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");
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int a = 15, b = 10, c = 1;
    if (Convert.ToBoolean(a) && (b > c))
    {
        Console.WriteLine("cquestionbank");
    }
    else
    {
        break;
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
 static void Main(string[] args)
 {
     int i;
     i = 0;
     while (i++ < 5)
     {
         Console.WriteLine(i);
     }
     Console.WriteLine("\n");
     i = 0;
     while ( ++i < 5)
    {
        Console.WriteLine(i);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{   
    int a = -1;
    int b = -1;
    if (Convert.ToBoolean (++a = ++b))
    Console.WriteLine("a");
    else
    Console.WriteLine("b");
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    long  x;
    x = Convert.ToInt32(Console.ReadLine());
    do
    {
        Console.WriteLine(x % 10);
    }while ((x = x / 10) != 0);
    Console.ReadLine();
}
enter x = 1234.

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i, s = 0;
    for (i = 1; i <= 10; s = s + i, i++);
    {
        Console.WriteLine(s);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    float f;
    for (f = 0.1f; f <= 0.5; f += 1)
    Console.WriteLine( ++f );
    Console.ReadLine();
}

Select an option to see the answer and solution.