C# Interview Questions and Answers for 5 years Experienced


1.What is C-Sharp (C#)?

C# is a type-safe, managed and object oriented language, which is compiled by .Net framework for generating intermediate language (IL).

2.Explain the types of comments in C#?

Below are the types of comments in C# –

Single Line Comment Eg : //

Multiline Comments Eg: /* */

XML Comments Eg : ///

3.So what makes your code really object-oriented?

In order to understand this, we must first analyze what benefits we can derive from OO. In order to do this, we must clearly understand its foundation. So given that C# is at its core object-oriented

4.What is Cohesion?

In OOPS we develop our code in modules. Each module has certain responsibilities. Cohesion shows how much a module responsibilities are strongly related.

Higher cohesion is always preferred. Higher cohesion benefits are:

  1. Improves maintenance of modules
  2. Increase reusability

5.Why are strings in C# immutable?

Immutable means string values cannot be changed once they have been created. Any modification to a string value results in a completely new string instance, thus an inefficient use of memory and extraneous garbage collection. The mutable System.Text.StringBuilder class should be used when string values will change.


Array stores the values or elements of same data type but array list stores values of different data types.

Arrays will use the fixed length but array list does not uses fixed length like array.

7.What are the fundamental principles of OO programming?

As a developer, you might be tempted to answer that it comprises things like Encapsulation, Polymorphism, Abstraction, and Inheritance. Although this is true, it doesn’t really explain the fundamental core of what OO is and what its benefits are.

Principles are crucial but they are not the most important aspect of what OO actually is. What is really important is to understand in what grounds OO is built upon, or in other words, what are the foundations of OO programming.

The two most fundamental core concepts on which OO has been built upon in C# are this pointer and Dynamic Dispatch.

Obviously, there are principles like Encapsulation, Polymorphism, Abstraction, and Inheritance, but these are the consequence and not the generating force behind the OO paradigm in C#.

8.What is coupling?

OOPS Modules are dependent on each other. Coupling refers to level of dependency between two software modules.

Two modules are highly dependent on each other if you have changed in one module and for supporting that change every time you have to change in dependent module.

Loose Coupling is always preferred.

Inversion of Control and dependency injections are some techniques for getting loose coupling in modules.

9. What is the execution entry point for a C# console application?

The Main method.

10. Why to use “using” in C#?

“Using” statement calls – “dispose” method internally, whenever any exception occurred in any method call and in “Using” statement objects are read only and cannot be reassignable or modifiable.

11. What is the this Pointer?

The this pointer is silently passed with a call to an instance-level function, which then operates on an object (instance of a class).

Basically, this core mechanism makes it possible to bring operations close to data. It also eliminates the need to have global functions and it gives data structures the intrinsic ability to perform operations on its data.

12.What is Abstraction?

Abstraction is a technique of taking something specific and making it less specific.

In OOPS we achieve the abstraction by separating the implementation from interface. We take a implemented class and took only those method signatures and properties which are required by the class client. We put these method signatures and properties into interface or abstract class.

13. How do you initiate a string without escaping each backslash?

You put an @ sign in front of the double-quoted string.

String ex = @”This has a carriage return\r\n”

14.Explain namespaces in C#?

Namespaces are containers for the classes. We will use namespaces for grouping the related classes in C#. “Using” keyword can be used for using the namespace in other namespace.

15. What is the OO fundamental idea using C# that allows a data structure to perform operations on its own data?

What would your answer be? Pretty obvious. The humble this pointer.

Notice that despite this being a mind-bending idea, we can already start to appreciate the bigger picture for which C# was designed.

The this pointer is basically a way for a data structure (object) to be able to access methods that allow itself to perform operations on its own data. It is a way to manage state within a data structure.

Now let’s talk a bit about the other core concept that takes this to the next level.

16.What is Encapsulation?

In non object oriented languages, data and behaviors are not tied together. That means any function in the program can modify the data.

In Encapsulation, we bind the data and behaviors in one object. Only defined behaviors in a class can modify the data. We hide the state of an object by using properties and methods. Clients of the object only see these behaviors and by only these behaviors clients can modify the data.

We also protect the data by using access specifiers. We put the private / protected keywords before data to protect it from the outside world.

17. What is the difference between a struct and a class?

Structs cannot be inherited. Structs are passed by value and not by reference. Structs are stored on the stack not the heap. The result is better performance with Structs.

18.Explain “static” keyword in C#?

“Static” keyword can be used for declaring a static member. If the class is made static then all the members of the class are also made static. If the variable is made static then it will have a single instance and the value change is updated in this instance.

19. What is a singleton?

A singleton is a design pattern used when only one instance of an object is created and shared; that is, it only allows one instance of itself to be created. Any attempt to create another instance simply returns a reference to the first one. Singleton classes are created by defining all class constructors as private. In addition, a private static member is created as the same type of the class, along with a public static member that returns an instance of the class. Here is a basic example:

public class SingletonExample { private static SingletonExample _Instance; private SingletonExample () { } public static SingletonExample Get Instance() {  if (_Instance == null)  {    _Instance = new SingletonExample ();   }   return _Instance;  }}

20.Why to use “finally” block in C#?

“Finally” block will be executed irrespective of exception. So while executing the code in try block when exception is occurred, control is returned to catch block and at last “finally” block will be executed. So closing connection to database / releasing the file handlers can be kept in “finally” block.

21.What is boxing?

Boxing is the process of explicitly converting a value type into a corresponding reference type. Basically, this involves creating a new object on the heap and placing the value there. Reversing the process is just as easy with unboxing, which converts the value in an object reference on the heap into a corresponding value type on the stack. The unboxing process begins by verifying that the recipient value type is equivalent to the boxed type. If the operation is permitted, the value is copied to the stack

22.Can we have only “try” block without “catch” block in C#?

Yes we can have only try block without catch block.

23. How to move to a State-related Codebase?

So now that we’ve explored these concepts, let’s move to a state-related code base. So you might be asking yourself at this moment

24.What is the difference between “out” and “ref” parameters in C#?

“out” parameter can be passed to a method and it need not be initialized where as “ref” parameter has to be initialized before it is used.

25.How are methods overloaded?

Methods are overloaded via different signatures (number of parameters and types). Thus, you can overload a method by having different data types, different number of parameters, or a different order of parameters.

26.Explain Jagged Arrays in C#?

If the elements of an array is an array then it’s called as jagged array. The elements can be of different sizes and dimensions.

27.How do you prevent a class from being inherited?

The sealed keyword prohibits a class from being inherited.

28.What you mean by inner exception in C#?


29.What is the GAC, and where is it located?

The GAC is the Global Assembly Cache. Shared assemblies reside in the GAC; this allows applications to share assemblies instead of having the assembly distributed with each application. Versioning allows multiple assembly versions to exist in the GAC—applications can specify version numbers in the config file. The gacutil command line tool is used to manage the GAC.

30.Explain circular reference in C#?


Review Date
Reviewed Item
Being a Working Professional C# Interview Questions and Answers for 5 years Experienced were very useful for me, thank you myTectra.
Author Rating

Recommended Posts