C# (C-Sharp) Interview Questions and Answers

C-Sharp or C# is modern and general programming language and is one of the most populous language. C-Sharp interview questions along with answers. These interview question and answers are most commonly asked in the interview. The C# programming language is based on Microsoft .NET framework. More C# interview questions will be added soon, Stay tune.

1. What is C# programming language?

C# programming language was developed by Microsoft. C# is modern, simple and object oriented programming language.

2. Define Class and Object?

  • Class defines methods (functions) and members (variables) that are included in object. Class is the blueprint used to create object. Memory is not allocated, when class is created. Class is user-defined which can be used to defined methods & functions and declare objects.
  • An Object is instance of a class. Memory is allocated when it is first created. Object have sub-object while class can have multiple sub-class.

3. Write Hello World program using C#?

4. What is jagged array?

Jagged arrays are arrays of arrays. The elements of jagged arrays are reference type and these elements are initialized to null.


5. What are Arrays in C#? How to declare arrays?

Arrays are used to stored multiple variables of same data types in array data. There are different types of arrays: single dimensional arrays, multi-dimensional arrays and jagged arrays. Below is the example for the declaration of arrays.

6. What is Substring? Explain with an example?

Substring in C# are used for extracting string from a given string. Substring begins from the index till the length of the string. For example, Fresher substring(3, 5) is she.


7. How to display current Date and Time in C#?

DateTime is used for displaying date and time .NET Framework. The following is the example for displaying current date and time.


8. Differentiate public, static and void?

Public is an access modifier keyword, so the Main method or class are accessible by anyone in the program.

9. What is inheritance?

Inheritance means acquiring the properties of parent class(base class) to the child class. In C#, inheritance is done by putting colon after the child class and it parent class i.e. class child : parent.

10. What is virtual keyword?

Virtual keyword is used for modifying methods, properties and thus helps overriding a base class.

11. What is ArrayList?

Unlike array, ArrayList can store variable of different datatypes. The size of the arraylist will either decrease or increase dynamically depending upon the datatype values.


12. What is partial class?

A class can be divided into several sub-class i.e. class1 + class2 = class. This is called as partial class.

13. What are the different version of C#?

C# Version Released Year
C# 1.0 2002
C# 2.0 2005
C# 3.0 2008
C# 4.0 2010
C# 5.0 2012

14. What is the use of var keyword?

var is implicit type variable. The compiler determines it types during compile time. It was first introduce in C# 3.0.

15. Difference between var and dynamic keyword?

var dynamic
var was introduce in C# 3.0 dynamic keyword was introduce in C# 4.0
The variable type will be declared during compile time by compiler The variable type will be declared during runtime by the compiler
The errors are caught during compile time Errors are always caught during runtime.