Top 74 C# Interview Questions

C# is an object-oriented programming language developed by Microsoft. C# code gets compiled into MSIL that further executes on CLR.

#61.

How dynamic array works? i.e. List, ArrayList, Hashtable etc.

#62.

protected vsinternal vs protected internal?

#63.

Does Overriding violate Liscove Substitution?

#64.

Why Static over Singleton or vice versa - Solid reason?

#65.

What happens when an exception is thrown in the lock?

#66.

What is GetHashCode() in C#?

#67.

Why static variables are not garbage collected?

#68.

Is static field initialization thread-safe?

#69.

When a static constructor is called?

#70.

Is Static class Thread Safe?

#71.

Explain memory allocation for static classes?

#72.

Problem #1 - Guess the output?

Employee emp = new Employee();
UpdateName(emp);
Console.WriteLine(emp.Name);

public void UpdateName(Employee emp)
{
    emp.Name = "Shiv";
}

#73.

Problem #2 - Guess the output?

Employee emp = new Employee();
UpdateName(emp);
Console.WriteLine(emp.Name);

public void UpdateName(Employee emp)
{
    emp = new Employee();
    emp.Name = "Max";
}

#74.

Problem #3 - Guess the output?

Employee emp = new Employee();
UpdateName_3(emp);
Console.WriteLine(emp.Name);

public void UpdateName_3(ref Employee emp)
{
    emp = new Employee();
    emp.Name = "Tom";
}