1. Question: Which of the following is used to create a conditional statement in C#?

    A
    if

    B
    for

    C
    while

    D
    switch

    Note: The if statement is used to execute code based on a condition.
    1. Report
  2. Question: What will the following code output?
    int x = 10;
    if (x > 5) Console.WriteLine("Greater");
    else Console.WriteLine("Smaller");

    A
    Greater

    B
    Smaller

    C
    10

    D
    Error

    Note: The condition x > 5 is true, so "Greater" is printed.
    1. Report
  3. Question: Which keyword is used to exit a loop prematurely in C#?

    A
    exit

    B
    stop

    C
    break

    D
    continue

    Note: The break statement is used to terminate the loop immediately.
    1. Report
  4. Question: What is the purpose of the continue statement in a loop?

    A
    To end the loop.

    B
    To skip the current iteration and continue with the next one.

    C
    To restart the loop.

    D
    To pause the loop.

    Note: To skip the current iteration and continue with the next one. Analysis: The continue statement skips the remaining code in the current loop iteration and proceeds to the next iteration.
    1. Report
  5. Question: What will the following code output?
    for (int i = 0; i < 3; i++) 
    {
        if (i == 1) continue;
        Console.WriteLine(i);
    }

    A
    0 1 2

    B
    0 2

    C
    1 2

    D
    0 1

    Note: When i is 1, the continue statement skips the output for that iteration.
    1. Report
  6. Question: Which of the following is a valid switch statement?
    switch (x) {
        case 1:
            break;
        default:
            break;
    }

    A
    Yes

    B
    No, it's incomplete

    C
    No, break cannot be used in case

    D
    No, default must come first

    Note: Not available
    1. Report
  7. Question: What will happen if no case matches in a switch statement?

    A
    It results in an error.

    B
    The program will crash.

    C
    The default case will execute if defined.

    D
    Nothing will happen.

    Note: If no cases match, the default block is executed, if it exists.
    1. Report
  8. Question: What will the following code print?
    int num = 2;
    switch (num) {
        case 1:
            Console.WriteLine("One");
            break;
        case 2:
            Console.WriteLine("Two");
            goto case 1;
        case 3:
            Console.WriteLine("Three");
            break;
        default:
            Console.WriteLine("Default");
            break;
    }

    A
    One

    B
    Two

    C
    One and Three

    D
    Default

    Note: The output is "Two" followed by "One" due to the goto case 1;, but "Three" is not printed because it would not execute after the goto.
    1. Report
  9. Question: What is the purpose of the if-else structure?

    A
    To loop through a set of values

    B
    To execute code based on multiple conditions.

    C
    To execute code conditionally based on true/false evaluations.

    D
    To declare variables.

    Note: The if-else structure allows execution of different code blocks based on whether a condition is true or false.
    1. Report
  10. Question: Which of the following correctly implements a while loop?

    A
    while (x < 5) { x++; }

    B
    while (x < 5) x++;

    C
    Both

    D
    None

    Note: Both forms are correct; The curly braces are optional if there is only one statement.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd