1. What will be the output of the following code?
int a = 5;
int b = ++a * 2;
Console.WriteLine(b);
a) 10
b) 12
c) 14
d) 11
2. Which of the following statements about `readonly` and `const` in C# is true?
a) Both `readonly` and `const` can be assigned at runtime.
b) `readonly` can be assigned at runtime, `const` cannot.
c) `const` can be assigned at runtime, `readonly` cannot.
d) Both `readonly` and `const` cannot be assigned at runtime.
3. What is the output of the following code?
string s1 = "hello";
string s2 = "hello";
Console.WriteLine(object.ReferenceEquals(s1, s2));
a) True
b) False
c) Depends on the compiler
d) Compilation Error
4. Which of the following is a correct way to declare a nullable integer in C#?
a) int? x = null;
b) nullable int x = null;
c) int x = nullable null;
d) int x = null;
5. What will be the output of the following code?
int x = 10;
int y = x++ + ++x;
Console.WriteLine(y);
a) 21
b) 22
c) 20
d) 23
6. Which of the following LINQ methods can be used to group elements?
a) Select()
b) GroupBy()
c) Where()
d) Aggregate()
7. What is the purpose of the `yield` keyword in C#?
a) To exit a method
b) To return multiple values from a method
c) To iterate over a collection
d) To define a delegate
8. What will be the output of the following code?
int[] numbers = { 1, 2, 3, 4 };
var result = numbers.Select(n => n * 2).Where(n => n > 4);
Console.WriteLine(result.Count());
a) 2
b) 3
c) 4
d) 1
9. Which of the following statements about interfaces in C# is true?
a) Interfaces can contain fields.
b) Interfaces can have constructors.
c) Interfaces can contain method implementations (from C# 8.0 onwards).
d) Interfaces cannot be inherited.
10. What is the output of the following code?
var list = new List<int> { 1, 2, 3 };
list.Insert(1, 5);
Console.WriteLine(string.Join(",", list));
a) 1,5,2,3
b) 1,2,3,5
c) 5,1,2,3
d) 1,2,5,3
11. Which of the following is true about the `dynamic` type in C#?
a) Type checking is done at compile time.
b) It is the same as `var`.
c) Type checking is deferred until runtime.
d) It cannot be used with methods.
12. What will be the output of the following code?
int x = 5;
int y = 10;
Console.WriteLine(x > y ? x : y);
a) 5
b) 10
c) True
d) False
13. Which of the following is not a value type in C#?
a) int
b) float
c) string
d) bool
14. What is the purpose of the `async` keyword in C#?
a) To define a synchronous method
b) To define a method that can run asynchronously
c) To pause the execution of a method
d) To define a delegate
15. What will be the output of the following code?
int[] arr = { 1, 2, 3 };
Array.Reverse(arr);
Console.WriteLine(arr[0]);
a) 1
b) 2
c) 3
d) 0
16. Which of the following is used to handle exceptions in C#?
a) try-catch block
b) if-else statement
c) switch statement
d) for loop
17. What is the output of the following code?
string s = "CSharp";
Console.WriteLine(s.Substring(1, 3));
a) Sha
b) har
c) CSh
d) Shar
18. Which of the following is not an access modifier in C#?
a) public
b) private
c) protected
d) internal protected
19. What will be the output of the following code?
int a = 5;
int b = 10;
Console.WriteLine(a & b);
a) 0
b) 5
c) 10
d) 15
20. Which of the following statements about delegates in C# is true?
a) Delegates are not type-safe.
b) Delegates can reference multiple methods.
c) Delegates cannot be passed as parameters.
d) Delegates are value types.