Set 1: C# Fundamentals
Section 1: Basic Syntax and Data Types
1.Which of the following statements is true about the 'var' keyword in C#?
○a) 'var' must be initialized at the time of declaration.
○b) 'var' can be used for any data type.
○c) 'var' is used for arrays only.
○d) 'var' can be used only for reference types
2.What is the default value of an uninitialized integer in C#?
○a) 0
○b) null
○c) undefined
○d) 0.0
3.Which of the following methods is used to convert a string to an integer in C#?
○a) Parse()
○b) Convert()
○c) Int()
○d) Both a and b
4.Which of these data types is a value type in C#?
○a) string
○b) int
○c) array
○d) object
5.Which of the following operators is used for checking null in C#?
○a) !=
○b) ==
○c) ??
○d) =>
What is the output of the following code snippet?
int x = 10;
Console.WriteLine(x++);
6.
○a) 10
○b) 11
○c) Error
○d) Nothing
7.Which of the following is NOT a valid C# loop?
○a) for
○b) foreach
○c) while
○d) repeat
8.What does the 'break' statement do in C#?
○a) Exits the current method
○b) Skips the current iteration of the loop
○c) Exits the loop entirely
○d) Continues to the next iteration of the loop
What will the following code print?
string s = "Hello";
Console.WriteLine(s.Length);
11.
○a) 5
○b) Hello
○c) 5.0
○d) Error
12.Which of the following keywords can be used to create a constant in C#?
○a) constant
○b) readonly
○c) static
○d) const
13.What will happen if you declare an array in C# with a size but do not initialize
its elements?
○a) The elements are automatically initialized to 0.
○b) The elements will throw an error when accessed.
○c) The array size will be null.
○d) None of the above.
What is the output of the following code?
csharp
Copy
int[] arr = {1, 2, 3, 4};
Console.WriteLine(arr[2]);
14.
○a) 1
○b) 2
○c) 3
○d) 4
15.Which of the following correctly declares a constant in C#?
○a) const int x = 5;
○b) readonly int x = 5;
○c) static int x = 5;
○d) None of the above
16.What is the default value of an uninitialized string in C#?
○a) ""
○b) null
○c) undefined
○d) 0
○Correct answer: b) null
21.Which of the following statements is true about constructors in C#?
○a) A constructor can have a return type.
○b) Constructors are called automatically when an object is instantiated.
○c) A class can have multiple constructors, but only one default constructor.
○d) Constructors must always take parameters.
22.Which type of inheritance is supported by C#?
○a) Multiple inheritance
○b) Single inheritance
○c) Multilevel inheritance
○d) Both b and c
23.What does the 'virtual' keyword mean when applied to a method in C#?
○a) The method cannot be overridden.
○b) The method can be called without creating an object.
○c) The method can be overridden in a derived class.
○d) The method must be overridden in every derived class.
24.Which C# feature allows different objects to respond to the same method call in
different ways?
○a) Polymorphism
○b) Encapsulation
○c) Abstraction
○d) Inheritance
25.In C#, which method signature is used to call the base class constructor from a
derived class?
○a) base()
○b) super()
○c) this()
○d) call()
Section 2: Object-Oriented Programming Concepts
21.Which of the following can be used to define an abstract method in C#?
○a) abstract
○b) virtual
○c) static
○d) sealed
22.What is the purpose of the new keyword in C# when defining a method in a derived
class?
○a) It is used to hide a base class method.
○b) It defines a new method that overrides the base class method.
○c) It makes the method static.
○d) None of the above
23.Which of the following is an example of polymorphism in C#?
○a) Method overloading
○b) Method overriding
○c) Both a and b
○d) None of the above
24.What is the purpose of the virtual keyword in C#?
○a) It indicates that a method can be overridden in a derived class.
○b) It makes the method abstract.
○c) It makes the method static.
○d) None of the above
25.Which of the following is used to call the base class constructor from a derived
class in C#?
○a) base()
○b) super()
○c) this()
○d) call()
26.Which of the following access modifiers allows a class to be accessed only
within its own assembly but not outside of it?
○a) public
○b) private
○c) internal
○d) protected
27.Which of the following is the purpose of the protected access modifier in C#?
○a) It allows access to the class from anywhere.
○b) It allows access only within the same class and derived classes.
○c) It allows access only within the same class.
○d) It allows access from the same assembly.
Section 3: Advanced Concepts in C#
31.Which of the following operators is used to invoke an event in C#?
○a) event()
○b) +=
○c) - =
○d) None of the above
32.Which of the following is used to define an immutable type in C#?
○a) readonly
○b) const
○c) sealed
○d) static
33.What will happen if you call a method asynchronously in C# without using the
await keyword?
○a) The method will run synchronously.
○b) The method will throw a compile-time error.
○c) The method will run asynchronously, but the calling thread will wait.
○d) The method will run asynchronously, but the calling thread will not wait.
38.Which of the following is used to prevent a class from being instantiated in C#?
○a) sealed
○b) static constructor
○c) abstract keyword
○d) private constructor
39.Which of the following is an example of inheritance in C#?
○a) A class derives from another class.
○b) A class implements an interface.
○c) A class uses delegates to invoke methods.
○d) A class defines multiple methods with the same name.
What is the output of the following code?
string str = "CSharp";
Console.WriteLine(str.Substring(2, 4));
40.
○a) CSh
○b) Shar
○c) CSharp
○d) Error
Set 3: C# Advanced Concepts and OOP
Section 1: Data Types, Control Structures, and Syntax
1.Which of the following is the correct way to declare a variable in C#?
○a) int x = 10;
○b) var x = 10;
○c) int x;
○d) All of the above
2.What is the default value of a float variable in C#?
○a) 0.0f
○b) 0.0
○c) null
○d) undefined
3.Which of the following is used to declare an array of integers in C#?
○a) int[] arr = {1, 2, 3};
○b) int arr[] = {1, 2, 3};
○c) int[] arr = new int[3];
○d) All of the above
What is the result of the following code?
int x = 5;
x *= 2;
Console.WriteLine(x);
4.
○a) 5
○b) 10
○c) 2
○d) Error
What will the following code print?
string s = "CSharp";
Console.WriteLine(s[1]);
5.
○a) C
○b) S
○c) H
○d) Sh
6.Which of the following is NOT a valid keyword in C#?
○a) for
○b) while
○c) do
○d) loop
7.Which of the following will throw an exception in C#?
○a) int.Parse("123")
○b) int.Parse("abc")
○c) int.TryParse("123", out result)
○d) Convert.ToInt32("abc")
8.Which of the following is used to append one string to another in C#?
○a) string.Concat()
○b) string.Append()
○c) string.Add()
○d) string.Merge()
9.Which of the following can be used to create a nullable type in C#?
○a) int? x;
○b) nullable<int> x;
○c) int x = null;
○d) None of the above
What will be the output of the following code?
string str = "CSharp";
Console.WriteLine(str.Substring(2, 3));
11.
○a) CSh
○b) Sharp
○c) Har
○d) Error
12.Which of the following is used to handle errors or exceptions in C#?
○a) try-catch
○b) throw-catch
○c) try-finally
○d) try-throw
13.What does the ?? operator do in C#?
○a) Checks if a variable is null.
○b) Returns the first non-null value.
○c) Assigns a default value if the variable is null.
○d) None of the above
14.Which of the following is true about the ref keyword in C#?
○a) It passes a variable by value.
○b) It passes a variable by reference.
○c) It is used for nullable types only.
○d) It allows passing a variable to a method without modifying it.
15.What is the purpose of the static keyword in C#?
○a) It allows a method to be called without creating an instance of the class.
○b) It makes a method abstract.
○c) It defines a class that cannot be inherited.
○d) It prevents method overloading.
16.What is the default value of an uninitialized reference type in C#?
○a) 0
○b) null
○c) false
○d) undefined
What is the output of the following code?
int[] arr = { 1, 2, 3, 4 };
arr[1] = 10;
Console.WriteLine(arr[1]);
17.
○a) 1
○b) 2
○c) 10
○d) 4
18.Which of the following is used to define an immutable string in C#?
○a) string s = "Hello";
○b) string s = new String("Hello");
○c) StringBuilder s = new StringBuilder("Hello");
○d) None of the above
19.Which of the following is the correct way to define a method in C# that returns
an integer?
○a) int methodName() { return 5; }
○b) methodName() { return 5; }
○c) int methodName() => 5;
○d) int methodName() : 5;
20.Which of the following methods can be used to parse a string to a float?
○a) float.Parse()
○b) Convert.ToSingle()
○c) float.TryParse()
○d) All of the above
Section 2: Object-Oriented Programming (OOP)
21.Which of the following is used to prevent a class from being inherited in C#?
○a) sealed
○b) abstract
○c) static
○d) readonly
22.Which of the following can be used to define a method in a base class that can
be overridden in a derived class?
○a) abstract
○b) virtual
○c) override
○d) None of the above
23.Which of the following allows multiple methods with the same name but different
parameters in C#?
○a) Method overloading
○b) Method overriding
○c) Inheritance
○d) Polymorphism
24.Which of the following is true about the base keyword in C#?
○a) It refers to the base class constructor.
○b) It calls a method from the derived class.
○c) It calls the default constructor of the derived class.
○d) It is used to define an abstract method.
25.Which of the following is used to define a read-only property in C#?
○a) readonly
○b) const
○c) static
○d) get