C# Coding MCQ Questions and Answers

Welcome to C# Programming Coding MCQ Questions. Here, we present 20 MCQs (Multiple-Choice Questions) with code snippets to test your understanding of C# programming coding and logical stills. Let's get started!

1. What will the following C# code output?

using System;
class Program {
    static void Main() {
        Console.WriteLine(10 + 5 + "Hello");
    }
}
a) 15Hello
b) Hello15
c) 105Hello
d) Compilation Error

2. What does this C# code snippet output?

using System;
class Program {
    static void Main() {
        Console.WriteLine(8 % 3);
    }
}
a) 2
b) 2.67
c) 3
d) 0

3. Consider the following C# code. What will it print?

using System;
class Program {
    static void Main() {
        int x = 10;
        Change(ref x);
        Console.WriteLine(x);
    }
    static void Change(ref int n) {
        n = 20;
    }
}
a) 10
b) 20
c) 0
d) Compilation Error

4. What is the output of the following C# function?

using System;
class Program {
    static void Main() {
        string s1 = "hello";
        string s2 = "hello";
        Console.WriteLine(s1 == s2);
    }
}
a) True
b) False
c) Error
d) Null

5. What will this C# program output?

using System;
class Program {
    static void Main() {
        Console.WriteLine("5" + 2 + 3);
    }
}
a) 10
b) 5
c) 523
d) 53

6. Analyze the following C# code snippet. What is its output?

using System;
class Program {
    static void Main() {
        Console.WriteLine((10.5).GetType().Name);
    }
}
a) double
b) Decimal
c) Float
d) Int

7. Consider the following C# code. What will it print?

using System;
class Program {
    static void Main() {
        int i = 0;
        Console.WriteLine(i++);
    }
}
a) 0
b) 1
c) Compilation error
d) Runtime error

8. What does this C# code output?

using System;
class Program {
    static void Main() {
        int x = 5;
        Console.WriteLine(x > 3 ? "Yes" : "No");
    }
}
a) Yes
b) No
c) 3
d) 5

9. What will the following C# code print?

using System;
class Program {
    static void Main() {
        var numbers = new[] { 1, 2, 3 };
        Console.WriteLine(numbers.Length);
    }
}
a) 3
b) 4
c) 2
d) Compilation error

10. What does the following C# program output?

using System;
class Program {
    static void Main() {
        int? x = null;
        Console.WriteLine(x ?? -1);
    }
}
a) null
b) -1
c) 0
d) Error

11. Analyze the following C# code snippet. What will it output?

using System;
class Program {
    static void Main() {
        int x = 5;
        int y = ++x;
        Console.WriteLine(y);
    }
}
a) 5
b) 6
c) 7
d) Error

12. What will the following C# code output?

using System;
class Program {
    static void Main() {
        Console.WriteLine("Hello".ToUpper());
    }
}
a) HELLO
b) hello
c) Hello
d) Compilation Error

13. Consider the following C# code. What will it print?

using System;
class Program {
    static void Main() {
        double result = 10 / 4;
        Console.WriteLine(result);
    }
}
a) 2.5
b) 2
c) 2.0
d) None of the above

14. What is the output of the following C# function?

using System;
class Program {
    static void Main() {
        Console.WriteLine("abc".Substring(1, 2));
    }
}
a) ab
b) bc
c) b
d) abc

15. What will this C# program output?

using System;
class Program {
    static void Main() {
        bool flag = 10 > 9 && 5 > 4;
        Console.WriteLine(flag);
    }
}
a) True
b) False
c) Compilation error
d) None

16. What does the following C# code snippet output?

using System;
class Program {
    static void Main() {
        int[] array = {1, 2, 3};
        Modify(array);
        Console.WriteLine(array[0]);
    }
    static void Modify(int[] array) {
        array[0] = 10;
    }
}
a) 1
b) 10
c) Error
d) 0

17. Consider the following C# code. What will it print?

using System;
class Program {
    static void Main() {
        string s = "Hello";
        string t = s;
        t += " World";
        Console.WriteLine(s);
    }
}
a) Hello World
b) Hello
c) HelloHello
d) Compilation error

18. What does the following C# code output?

using System;
class Program {
    static void Main() {
        int? x = null;
        Console.WriteLine(x.HasValue);
    }
}
a) True
b) False
c) Error
d) null

19. What will the following C# code print?

using System;
class Program {
    static void Main() {
        var list = new System.Collections.Generic.List<int>{1, 2, 3};
        list.Remove(2);
        Console.WriteLine(list.Count);
    }
}
a) 2
b) 3
c) 1
d) Compilation error

20. What does this code snippet output?

using System;
class Program {
    static void Main() {
        int i = 3;
        while(i-- > 0) {
            Console.WriteLine(i);
        }
    }
}
a) 3 2 1
b) 2 1 0
c) 2 1
d) 1 0

Comments