Skip to content
C# Basic MCQs
- What is the correct file extension for a C# program file?
- a) .cs
- b) .csharp
- c) .c
- d) .cpp
- Which of the following is a valid way to declare a variable in C#?
- a) int x;
- b) int x = 10;
- c) x = 10;
- d) Both a and b
- Which of the following types can hold a decimal number in C#?
- a) int
- b) float
- c) double
- d) Both b and c
- What keyword is used to create a new class in C#?
- a) class
- b) create
- c) new
- d) define
- Which of the following statements is true about arrays in C#?
- a) Arrays can hold multiple data types.
- b) The size of an array is dynamic.
- c) Array index starts from 0.
- d) Arrays cannot be resized.
- How do you declare a constant in C#?
- a) const int MY_CONSTANT = 10;
- b) int const MY_CONSTANT = 10;
- c) constant int MY_CONSTANT = 10;
- d) final int MY_CONSTANT = 10;
- What is the output of the following code:
Console.WriteLine(5 + 10);?
- a) 15
- b) 510
- c) Error
- d) 5 and 10
- Which of the following is used to handle exceptions in C#?
- a) try-catch
- b) except
- c) finally
- d) handle
- In C#, which keyword is used for inheritance?
- a) extends
- b) implements
- c) inherits
- d) :
- What is the default value of a boolean variable in C#?
- a) true
- b) false
- c) 0
- d) null
- Which of the following is not a C# access modifier?
- a) public
- b) private
- c) static
- d) protected
- How do you create a single-line comment in C#?
- a) // This is a comment
- b) /* This is a comment */
- c) # This is a comment
- d) — This is a comment
- What does the
static keyword indicate in a method declaration?
- a) The method can only be called from another class.
- b) The method belongs to the class itself rather than instances of the class.
- c) The method will not return any value.
- d) None of the above.
- Which of the following is a correct way to declare a method in C#?
- a) void MyMethod() { }
- b) MyMethod void() { }
- c) method void MyMethod() { }
- d) function void MyMethod() { }
- What does the
new keyword do in C#?
- a) It declares a variable.
- b) It initializes an object.
- c) It creates a new class.
- d) All of the above.
- What is the purpose of the
using statement in C#?
- a) To include namespaces.
- b) To create classes.
- c) To define variables.
- d) To handle exceptions.
- Which of the following statements is used to exit a loop in C#?
- a) exit
- b) break
- c) stop
- d) return
- What is the size of an
int variable in C#?
- a) 2 bytes
- b) 4 bytes
- c) 8 bytes
- d) Depends on the system
- In C#, how do you check if a string is empty?
- a) String.IsNullOrEmpty(myString);
- b) myString.IsEmpty();
- c) myString.Length == 0;
- d) Both a and c.
- Which operator is used to assign a value to a variable in C#?
- What is the valid way to create an interface in C#?
- a) interface IMyInterface { }
- b) interface MyInterface { }
- c) class IMyInterface { }
- d) interface: IMyInterface { }
- Which of the following collections allows duplicate elements in C#?
- a) HashSet
- b) Dictionary
- c) List
- d) Queue
- What method is called when an object is created in a class?
- a) Main
- b) Constructor
- c) Method
- d) Init
- How can you convert an integer to a string in C#?
- a) Convert.ToString(myInt);
- b) myInt.ToString();
- c) string(myInt);
- d) Both a and b.
- What is the purpose of the
override keyword in C#?
- a) To create a new method.
- b) To change the implementation of a base class method.
- c) To prevent a method from being overridden.
- d) None of the above.
- What is the correct way to declare a nullable type in C#?
- a) int? x;
- b) Nullable<int> x;
- c) Both a and b.
- d) int x?;
- Which of the following is a valid tuple declaration in C#?
- a) var myTuple = (1, “Hello”);
- b) var myTuple: (int, string) = (1, “Hello”);
- c) Tuple<int, string> myTuple = (1, “Hello”);
- d) myTuple = (1, “Hello”);
- What operator is used for string concatenation in C#?
- Which of the following is a primitive data type in C#?
- a) String
- b) List
- c) int
- d) Dictionary
- How do you prevent a class from being inherited in C#?
- a) sealed
- b) private
- c) protected
- d) final
- What is the purpose of a
delegate in C#?
- a) To create an object.
- b) To hold a reference to a method.
- c) To manage memory.
- d) To define a class.
- Which of the following is used to define an enum in C#?
- a) enum Colors { Red, Green, Blue }
- b) enum Colors: { Red, Green, Blue }
- c) Colors { Red, Green, Blue }
- d) def enum Colors { Red, Green, Blue }
- How can you make a method generic in C#?
- a) public void MyMethod<T>() { }
- b) public void MyMethod(T) { }
- c) generic void MyMethod() { }
- d) public MyMethod<T>() { }
- What does the
params keyword in C# signify?
- a) It’s used for exceptions.
- b) It allows passing a variable number of arguments to a method.
- c) It’s for array declarations.
- d) None of the above.
- Which of the following allows multiple methods with the same name in C#?
- a) Abstraction
- b) Polymorphism
- c) Inheritance
- d) Encapsulation
- Which of the following is the correct way to declare a property in C#?
- a) public int Property { get; set; }
- b) public int Property() { }
- c) public int Property: get; set;
- d) int Property { }
- How do you create a read-only property in C#?
- a) public int Property { get; }
- b) public int Property() { return 0; }
- c) public int Property: get;
- d) int Property { return 0; }
- What does the
ref keyword mean when passed as a parameter in C#?
- a) It creates a copy of the argument.
- b) It allows the method to modify the passed argument.
- c) It prevents modification of the argument.
- d) None of the above.
- Which of the following is not a valid loop statement in C#?
- a) for
- b) while
- c) repeat
- d) do-while
- What is the purpose of the
finally block in C#?
- a) To execute code when an exception is caught.
- b) To execute code regardless of whether an exception occurred.
- c) To define a method.
- d) To create a loop.
- In C#, which of the following is used to import namespaces?
- a) include
- b) import
- c) using
- d) require
- What does the
async keyword signify in a method in C#?
- a) The method is synchronous.
- b) The method runs on a separate thread.
- c) The method can contain
await statements.
- d) Both b and c.
- Which method is called when the application starts in C#?
- a) Run
- b) Start
- c) Main
- d) Init
- What does
LINQ stand for in C#?
- a) Language Integrated Query
- b) Language Interfaced Queue
- c) Language Interactive Query
- d) None of the above.
- What is a
namespace in C# used for?
- a) To organize code.
- b) To define class attributes.
- c) To create methods.
- d) None of the above.
- How do you create an instance of a class in C#?
- a) MyClass myObj = new MyClass();
- b) var myObj = new MyClass();
- c) Both a and b.
- d) Class MyClass = new myObj();
- What does the
override keyword do when applied to a method?
- a) Defines a new method.
- b) Changes the accessibility of a method.
- c) Modifies a base class’s method implementation.
- d) Prevents a method from being overridden.
- Which of the following is the correct syntax for an
if statement in C#?
- a) if (condition) { }
- b) if condition { }
- c) if (condition) then { }
- d) if [condition] { }
- How do you define a list in C#?
- a) List<int> myList = new List<int>();
- b) int[] myList = new List<int>();
- c) myList = new List<int>();
- d) List myList = new List<int>();
- What is the purpose of
readonly in C#?
- a) To declare variables that can be changed.
- b) To declare properties that can only be set in the constructor.
- c) To create constants.