Following quiz provides Multiple Choice Questions (MCQs) related to C#. You will have to read all the given answers and choose over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer link.
1. Which of the following variable types can be assigned a value directly in C#?
A – Value types
B – Reference types
C – Pointer types
D – All of the above
Explaination: Value type variables can be assigned a value directly.
2. Which of the following is correct about value type variables in C#?
A – The value types directly contain data.
B – int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively are value types.
C – When you declare an int type, the system allocates memory to store the value.
D – All of the above.
Explaination: All of the above options are correct.
3. Which of the following converts a type to a 16-bit integer in C#?
A – ToDecimal
B – ToDouble
C – ToInt16
D – ToInt32
Explaination: ToInt16() method converts a type to a 16-bit integer.
4. Which of the following operator returns the type of a class in C#?
A – sizeof
B – typeof
C – &
D – *
Explaination: typeof() operator returns the type of a class.
5. Which of the following access specifier in C# allows a child class to access the member variables and member functions of its base class?
A – Public
B – Private
C – Protected
D – Internal
Explaination: Protected access specifier allows a child class to access the member variables and member functions of its base class.
6. Which of the following is true about C# structures?
A – Structures can have methods, fields, indexers, properties, operator methods, and events.
B – Structures can have defined constructors, but not destructors.
C – You cannot define a default constructor for a structure. The default constructor is automatically defined and cannot be changed.
D – All of the above.
Explaination: All of the above options are correct.
7. Which of the following is the default access specifier of a class member variable?
A – Private
B – Public
C – Protected
D – Internal
Explaination: Default access for the class member variables is Private.
8. Which of the following is the correct about interfaces in C#?
A – Interfaces are declared using the interface keyword.
B – Interface methods are public by default.
C – Both of the above.
D – None of the above.
Explaination: Both of the above options are correct.
9. Which of the following preprocessor directive allows testing a symbol or symbols to see if they evaluate to true in C#?
A – define
B – undef
C – if
D – elif
Explaination: #if − It allows testing a symbol or symbols to see if they evaluate to true.
10. The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown.
A – true
B – false
Explaination: The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown.
easy
LikeLike