Link Search Menu Expand Document

10 Important C# Interview Questions and Answers

Here is a list of crucial C# interview questions and answers that help students to prepare and achieve success in their interviews.

1. What is a Base class in C#?

Ans: A base class is a class used to build other classes, and classes such as subclass, child class, etc. are considered to obtain from the base class. A base class does not exhibit inheritance and is known as the parent class.

2. Mention the various types of statements in C#.

Ans:

  • Block statements – Block statements are a collection of multiple statements and are represented using {} [curly braces].
  • Declaration statements – Declaration statements are used to assign a value and a data type to variables.
  • Expression statements – Expression statements are statements that end with a semicolon (;).
  • Selection statements – Selection statements are also known as conditional statements and are statements that validate certain conditions and run the code according to the validation.
  • Iteration statements – Iteration statements are also known as loop statements that run multiple times according to the loop state.

3. Define StreamReader and StreamWriter class.

Ans: StreamReader and StreamWriter classes are an extended version of TextReader and TextWriter classes. A StreamReader retrieves information from a file, whereas a StreamWriter transmits data to a file.

4. Describe Deadlock in C#.

Ans: Deadlock is a scenario where multiple threads remain constant and wait for one another to complete their task.

5. Define caching in C#.

Ans: Caching is a method of collecting commonly used data to be reused whenever needed instead of writing the data again.

6. Explain about custom control and user control

Ans: Custom controls are simpler to use and can be built as source code and improve the system’s efficiency. User controls are interchangeable controls that use the same methods used by various other web mechanisms.

7. Distinguish between Array and ArrayList.

Ans: An Array is represented using [ ] (square braces). The array allows you to store a collection of values in a single variable rather than assigning different variables for every value. ArrayList is a substitute for an array. It reflects a systematic collection of entities having different values and data types. This collection can be independently sorted whose size is not constant and randomly increase in size.

8. What are indexers in C#?

Ans: Indexers are also referred to as smart arrays represented using [ ] (square brackets). They are used to build easily using objects. There are three different types of indexers such as custom indexers, generic indexers, and overload indexers.

9. Distinguish between direct cast and Ctype

Ans: In general, Direct cast is used to express object types, whereas the Ctype is used to define data types. Directcast throws an InvalidCastException during execution while Ctype will not throw any exceptions during the performance.

10. Define the Console application in C#.

Ans: A console application is an application that receives input and produces output on a command prompt that can run on windows. It comes with three specific streams, such as custom input, custom output, and custom error.

Other useful articles:


Back to top

© , CsharpOnline.com — All Rights Reserved - Terms of Use - Privacy Policy