Are you ready to test your knowledge and sharpen your skills in C# programming? Whether you’re a beginner looking to solidify your understanding or an experienced developer seeking a fun challenge, this blog post is here to help you. We have compiled a collection of 100 multiple-choice questions and answers on C# that cover a wide range of topics, allowing you to assess your grasp of the language.
C# is a powerful programming language widely used for developing a variety of applications, including desktop software, web applications, and mobile apps. Having a strong foundation in C# is essential for any aspiring or professional software developer. By diving into these multiple-choice questions, you’ll not only gauge your knowledge but also gain insights into different aspects of C# programming.
Question
Option A
Option B
Option C
Option D
Answer
1. Which of the following is NOT a primitive data type in C#?
int
double
string
bool
string
2. What is the default access modifier for a class member in C#?
public
private
protected
internal
private
3. What is the purpose of the var keyword in C#?
To implicitly declare a local variable with inferred type
To create an instance of a class
To perform arithmetic calculations
To define a loop construct
To implicitly declare a local variable with inferred type
4. Which keyword is used to define a constant in C#?
const
final
static
constant
const
5. What is the purpose of the using statement in C#?
To import namespaces or define resource scope
To compare two variables
To perform logical operations
To define a loop construct
To import namespaces or define resource scope
6. Which of the following is NOT a valid access modifier in C#?
public
private
protected
friendly
friendly
7. What is the purpose of the static keyword in C#?
To define class-level variables or methods
To create multiple instances of a class
To prevent a class from being inherited
To throw an exception
To define class-level variables or methods
8. Which of the following is NOT a valid C# loop statement?
for
while
until
do-while
until
9. What is the purpose of the abstract keyword in C#?
To define a base class or method that must be overridden
To perform bitwise operations
To manage memory allocation for objects
To exit a loop or switch statement
To define a base class or method that must be overridden
10. Which keyword is used to inherit a class in C#?
inherits
extends
implements
derives
inherits
Question
Option A
Option B
Option C
Option D
Answer
11. What is the purpose of the delegate keyword in C#?
To define a type that represents a method signature
To perform mathematical calculations
To define a conditional statement
To compare two variables
To define a type that represents a method signature
12. Which of the following is NOT a valid C# access modifier?
public
private
protected
internal
internal
13. What is the purpose of the try-catch statement in C#?
To handle exceptions and perform error handling
To declare a variable
To define a loop construct
To perform logical operations
To handle exceptions and perform error handling
14. Which keyword is used to create an instance of a class in C#?
new
create
instance
instantiate
new
15. What is the purpose of the interface keyword in C#?
To define a contract for implementing classes
To perform arithmetic operations
To define a loop construct
To compare two variables
To define a contract for implementing classes
16. Which of the following is NOT a valid C# conditional operator?
>
<
==
<>
<>
17. What is the purpose of the foreach statement in C#?
To iterate over elements in a collection or array
To sort elements in a collection
To perform bitwise operations
To exit a loop or switch statement
To iterate over elements in a collection or array
18. Which keyword is used to prevent a class from being inherited in C#?
sealed
static
final
protected
sealed
19. What is the purpose of the StringBuilder class in C#?
To create mutable strings
To compare two variables
To manage memory allocation for objects
To define a base class
To create mutable strings
20. Which of the following is NOT a valid C# exception handling keyword?
try
catch
finally
else
else
Question
Option A
Option B
Option C
Option D
Answer
21. What is the purpose of the out keyword in C#?
To pass arguments by reference and return multiple values
To declare a variable
To define a loop construct
To perform logical operations
To pass arguments by reference and return multiple values
22. Which of the following is NOT a valid C# data type modifier?
public
private
static
readonly
public
23. What is the purpose of the this keyword in C#?
To refer to the current instance of a class
To create an instance of a class
To define a loop construct
To compare two variables
To refer to the current instance of a class
24. Which keyword is used to handle the cleanup of unmanaged resources in C#?
using
dispose
cleanup
release
using
25. What is the purpose of the as operator in C#?
To perform type casting with safe conversion
To perform arithmetic calculations
To define a conditional statement
To exit a loop or switch statement
To perform type casting with safe conversion
26. Which of the following is NOT a valid C# access specifier?
public
private
protected
friendly
friendly
27. What is the purpose of the yield keyword in C#?
To create an iterator for a collection
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To create an iterator for a collection
28. Which keyword is used to handle exceptional conditions in C#?
try
catch
throw
finally
throw
29. What is the purpose of the enum keyword in C#?
To define a set of named constants
To compare two variables
To perform logical operations
To define a loop construct
To define a set of named constants
30. Which of the following is NOT a valid C# control flow statement?
if-else
switch
for
while-else
while-else
Question
Option A
Option B
Option C
Option D
Answer
31. What is the purpose of the async and await keywords in C#?
To enable asynchronous programming and simplify handling of asynchronous tasks
To perform mathematical calculations
To define a loop construct
To compare two variables
To enable asynchronous programming and simplify handling of asynchronous tasks
32. Which of the following is NOT a valid C# access level?
public
private
protected
internal
internal
33. What is the purpose of the lambda expression in C#?
To create anonymous functions
To declare a variable
To perform logical operations
To define a loop construct
To create anonymous functions
34. Which keyword is used to perform early termination of a loop in C#?
break
exit
continue
return
break
35. What is the purpose of the nameof operator in C#?
To obtain the name of a variable, type, or member as a string
To perform arithmetic operations
To define a conditional statement
To iterate over elements in a collection or array
To obtain the name of a variable, type, or member as a string
36. Which of the following is NOT a valid C# exception handling block?
try
catch
finally
else
else
37. What is the purpose of the ref keyword in C#?
To pass arguments by reference
To create an instance of a class
To perform bitwise operations
To exit a loop or switch statement
To pass arguments by reference
38. Which keyword is used to create an abstract method in C#?
abstract
virtual
override
sealed
abstract
39. What is the purpose of the lock keyword in C#?
To synchronize access to shared resources in a multi-threaded environment
To compare two variables
To manage memory allocation for objects
To define a base class
To synchronize access to shared resources in a multi-threaded environment
40. Which of the following is NOT a valid C# data type?
int
float
decimal
number
number
Question
Option A
Option B
Option C
Option D
Answer
41. What is the purpose of the params keyword in C#?
To pass a variable number of arguments to a method
To declare a constant value
To define a loop construct
To perform logical operations
To pass a variable number of arguments to a method
42. Which of the following is NOT a valid C# access modifier?
public
private
protected
friendly
friendly
43. What is the purpose of the base keyword in C#?
To access members of the base class
To create an instance of a class
To define a conditional statement
To compare two variables
To access members of the base class
44. Which keyword is used to explicitly inherit an interface in C#?
implements
extends
inherits
interface
implements
45. What is the purpose of the default keyword in C#?
To initialize variables with their default values
To perform arithmetic calculations
To define a loop construct
To exit a loop or switch statement
To initialize variables with their default values
46. Which of the following is NOT a valid C# bitwise operator?
&
`
`
~
%
47. What is the purpose of the sealed keyword in C#?
To prevent a class from being inherited
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To prevent a class from being inherited
48. Which keyword is used to specify a variable that cannot be modified in C#?
readonly
constant
immutable
static
readonly
49. What is the purpose of the nameof operator in C#?
To obtain the name of a variable, type, or member as a string
To compare two variables
To perform logical operations
To iterate over elements in a collection or array
To obtain the name of a variable, type, or member as a string
50. Which of the following is NOT a valid C# loop statement?
for
while
until
do-while
until
Question
Option A
Option B
Option C
Option D
Answer
51. What is the purpose of the using statement in C#?
To automatically release resources
To perform arithmetic calculations
To define a loop construct
To compare two variables
To automatically release resources
52. Which of the following is NOT a valid C# access modifier?
public
private
protected
friendly
friendly
53. What is the purpose of the static keyword in C#?
To define members that belong to the class itself, rather than instances of the class
To create an instance of a class
To define a conditional statement
To exit a loop or switch statement
To define members that belong to the class itself, rather than instances of the class
54. Which keyword is used to specify that a method overrides a base class method in C#?
override
virtual
new
base
override
55. What is the purpose of the checked keyword in C#?
To enable overflow checking for arithmetic operations
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To enable overflow checking for arithmetic operations
56. Which of the following is NOT a valid C# logical operator?
&&
`
`
!
57. What is the purpose of the abstract keyword in C#?
To define a class that cannot be instantiated and can only be inherited
To compare two variables
To perform logical operations
To iterate over elements in a collection or array
To define a class that cannot be instantiated and can only be inherited
58. Which keyword is used to specify that a method can be overridden in a derived class in C#?
virtual
override
new
base
virtual
59. What is the purpose of the var keyword in C#?
To infer the type of a variable at compile time
To declare a constant value
To define a loop construct
To perform arithmetic calculations
To infer the type of a variable at compile time
60. Which of the following is NOT a valid C# relational operator?
==
!=
>
:=
:=
Question
Option A
Option B
Option C
Option D
Answer
61. What is the purpose of the readonly keyword in C#?
To declare a variable that can only be assigned a value at the time of declaration or in a constructor
To perform arithmetic calculations
To define a loop construct
To exit a loop or switch statement
To declare a variable that can only be assigned a value at the time of declaration or in a constructor
62. Which of the following is NOT a valid C# access modifier?
public
private
protected
friendly
friendly
63. What is the purpose of the delegate keyword in C#?
To define a reference type that can hold a method reference
To create an instance of a class
To define a conditional statement
To compare two variables
To define a reference type that can hold a method reference
64. Which keyword is used to specify that a method or class cannot be overridden or inherited in C#?
sealed
override
new
abstract
sealed
65. What is the purpose of the typeof operator in C#?
To obtain the type object of a specified type
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To obtain the type object of a specified type
66. Which of the following is NOT a valid C# assignment operator?
=
+=
++
*=
++
67. What is the purpose of the interface keyword in C#?
To define a contract for implementing a set of methods and properties
To perform logical operations
To iterate over elements in a collection or array
To define a loop construct
To define a contract for implementing a set of methods and properties
68. Which keyword is used to specify that a method or class can be accessed without creating an instance in C#?
static
instance
dynamic
this
static
69. What is the purpose of the using directive in C#?
To import namespaces and enable the use of types without fully qualifying their names
To compare two variables
To perform arithmetic calculations
To define a loop construct
To import namespaces and enable the use of types without fully qualifying their names
70. Which of the following is NOT a valid C# conditional operator?
? :
??
!:
?.
!:
Question
Option A
Option B
Option C
Option D
Answer
71. What is the purpose of the try-catch block in C#?
To handle and catch exceptions
To perform arithmetic calculations
To define a loop construct
To compare two variables
To handle and catch exceptions
72. Which of the following is NOT a valid C# access modifier?
public
private
protected
friendly
friendly
73. What is the purpose of the out keyword in C#?
To pass a parameter by reference and allow the method to modify its value
To create an instance of a class
To define a conditional statement
To exit a loop or switch statement
To pass a parameter by reference and allow the method to modify its value
74. Which keyword is used to specify that a class cannot be instantiated in C#?
abstract
virtual
sealed
static
abstract
75. What is the purpose of the sizeof operator in C#?
To obtain the size in bytes of a value type
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To obtain the size in bytes of a value type
76. Which of the following is NOT a valid C# unary operator?
++
--
!
~
~
77. What is the purpose of the partial keyword in C#?
To allow a class or struct to be defined in multiple source files
To compare two variables
To perform logical operations
To iterate over elements in a collection or array
To allow a class or struct to be defined in multiple source files
78. Which keyword is used to specify that a class member can be accessed by derived classes in C#?
protected
private
internal
base
protected
79. What is the purpose of the yield keyword in C#?
To define an iterator and generate a sequence of values
To perform arithmetic calculations
To define a loop construct
To exit a loop or switch statement
To define an iterator and generate a sequence of values
80. Which of the following is NOT a valid C# bitwise operator?
&
`
`
~
^
Question
Option A
Option B
Option C
Option D
Answer
81. What is the purpose of the nameof operator in C#?
To obtain the name of a variable, type, or member as a string
To perform arithmetic calculations
To define a loop construct
To compare two variables
To obtain the name of a variable, type, or member as a string
82. Which of the following is NOT a valid C# access modifier?
public
private
protected
friendly
friendly
83. What is the purpose of the ref keyword in C#?
To pass a parameter by reference and allow the method to modify its value
To create an instance of a class
To define a conditional statement
To exit a loop or switch statement
To pass a parameter by reference and allow the method to modify its value
84. Which keyword is used to specify that a class can be inherited in C#?
class
struct
sealed
base
class
85. What is the purpose of the as operator in C#?
To perform a safe type conversion or cast
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To perform a safe type conversion or cast
86. Which of the following is NOT a valid C# logical operator?
&&
`
`
!
87. What is the purpose of the override keyword in C#?
To indicate that a method overrides a base class method
To compare two variables
To perform logical operations
To iterate over elements in a collection or array
To indicate that a method overrides a base class method
88. Which keyword is used to specify that a class member belongs to the instance of a class in C#?
this
static
dynamic
const
this
89. What is the purpose of the params keyword in C#?
To allow a variable number of arguments to be passed to a method
To define a constant value
To define a loop construct
To perform arithmetic calculations
To allow a variable number of arguments to be passed to a method
90. Which of the following is NOT a valid C# loop statement?
for
while
until
do-while
until
Question
Option A
Option B
Option C
Option D
Answer
91. What is the purpose of the lock keyword in C#?
To synchronize access to a shared resource
To perform arithmetic calculations
To define a loop construct
To compare two variables
To synchronize access to a shared resource
92. Which of the following is NOT a valid C# access modifier?
public
private
protected
internal
internal
93. What is the purpose of the params keyword in C#?
To allow a variable number of arguments to be passed to a method
To create an instance of a class
To define a conditional statement
To exit a loop or switch statement
To allow a variable number of arguments to be passed to a method
94. Which keyword is used to specify that a class cannot be inherited in C#?
sealed
override
abstract
virtual
sealed
95. What is the purpose of the typeof operator in C#?
To obtain the type object of a specified type
To perform bitwise operations
To manage memory allocation for objects
To define a base class
To obtain the type object of a specified type
96. Which of the following is NOT a valid C# relational operator?
==
!=
>
<>
<>
97. What is the purpose of the async keyword in C#?
To define an asynchronous method that can be awaited
To compare two variables
To perform logical operations
To iterate over elements in a collection or array
To define an asynchronous method that can be awaited
98. Which keyword is used to specify that a class member can only be accessed within the same assembly in C#?
internal
protected
private
base
internal
99. What is the purpose of the using directive in C#?
To import namespaces and enable the use of types without fully qualifying their names
To perform arithmetic calculations
To define a loop construct
To exit a loop or switch statement
To import namespaces and enable the use of types without fully qualifying their names
100. Which of the following is NOT a valid C# bitwise operator?