C# interview question answers - Coding Sharp

C# interview question answers

Q-1: Which of the following statement is true?
a. try block must be followed by catch and finally block both.
b. try block must be followed by catch or finally block or both.
c. try block cannot include another try block.
d. All of the above.

Correct Answer: (b) try block must be followed by catch or finally block or both.

Q-2: Which of the following datatype can be used with enum?
a. Int
b. String
c. Boolean
4. All of the above

Correct Answer: (a) Int

Q-3: A partial class allows ________
a. Implementation of single class in multiple .cs files.
b. Declaration of multiple classes in a single .cs file.
c. Implementation of multiple interfaces to single class.
d. Multiple class inheritance.

Correct Answer: (a) Implementation of single class in multiple .cs files.

Q-4: C# class can inherit multiple ________
a. Class
b. Interface
c. Abstract class
d. Static class

Correct Answer: (b) Interface

Q-5: Struct is a _____.
a. Reference type
b. Value type
c. Class type
d. String type

Correct Answer: (b) Value type

Q-6: Which of the following is true for ReadOnly variables?
a. Value will be assigned at runtime.
b. Value will be assigned at compile time.
c. Value will be assigned when it accessed first time
d. None of the above

Correct Answer: (a) Value will be assigned at runtime.

Q-7: LINQ stands for ________.
a. Language Integrated Query
b. Local Integration Query
c. Language Included Query
d. Lazy Integrated Query

Correct Answer: (a) Language Integrated Query

Q-8: Which of the following is true for dynamic type in C#?
a. It allows multiple time declaration of a variable.
b. It allows compile time type checking
c. It escapes compile time type checking
d. None of the above.

Correct Answer: (c) It escapes compile time type checking

Q-9: String data type is ______.
a. Mutable
b. Immutable
c. Static
d. Value type

Correct Answer: (b) Immutable

Q-10: Which of the following is right way of declaring an array?
a. Int[] intArray = new int[];
b. Int intArray[] = new int[5];
c. Int[] intArray = new int[5];
d. Int[] intArray = new int[]{1, 2, 3, 4, 5};

Correct Answer: (c) Int[] intArray = new int[5];

Q-11: What is Nullable type?
a. It allows assignment of null to reference type.
b. It allows assignment of null to value type.
c. It allows assignment of null to static class.
d. None of the above.

Correct Answer: (b) It allows assignment of null to value type.

Q-12: Which of the following is a reference type in C#?
a. String
b. Long
c. Boolean
d. None of the above

Correct Answer: (a) String

Q-13: Data type of a variable declared using var will be assigned at _______.
a. Runtime
b. Compile time
c. CLR time
d. Application Initialization time.

Correct Answer: (b) Compile time

Q-14: 10 > 9 ? “10 is greater than 9” : “9 is greater than 10” is an example of _______
a. Ternary operator
b. Conditional operator
c. Greater than operator
d. Inverse operator

Correct Answer: (a) Ternary operator

Q-15: Which of the following statement is true?
a. A finally block may not execute every time
b. A finally block cannot include return or break keyword.
c. A finally block can come before catch block.
d. Multiple finally block is possible.

Correct Answer: (b) A finally block cannot include return or break keyword.

Q-16: What is indexer?
a. It allows an instance of a class to be indexed like an array
b. It allows enumerator with class
c. It creates index for instances of a class.
d. None of the above.

Correct Answer: (a) It allows an instance of a class to be indexed like an array

Q-17: Return type of Predicate <T>() is always a ______.
a. Integer
b. String
c. Boolean
d. Void

Correct Answer: (c) Boolean

Q-18: An array in C# starts with _____ index.
a. One
b. Zero
c. -1
d. None of the above

Correct Answer: (b) Zero

Q-19: Which of the followings are value types in C#?
a. Int32
b. Double
c. Decimal
d. All of the above

Correct Answer: (d) All of the above

Q-20: Func and Action are the types of ______.
a. Utility function
b. Delegate
c. Event
d. Generic class

Correct Answer: (b) Delegate