Explain String Builder class in C#?
This will represent the mutable string of characters and this class cannot be inherited. It allows us to Insert, Remove, Append and Replace the characters. “ToString()” method can be used for the final string obtained from StringBuilder. For example,
StringBuilder TestBuilder = new StringBuilder("Hello");
TestBuilder.Remove(2, 3); // result - "He"
TestBuilder.Insert(2, "lp"); // result - "Help"
TestBuilder.Replace('l', 'a'); // result - "Heap"

What is the difference between “StringBuilder” and “String” in C#?

  • StringBuilder is mutable, which means once object for stringbuilder is created, it later be modified either using Append, Remove or Replace.
  • String is immutable and it means we cannot modify the string object and will always create new object in memory of string type.

What is the difference between methods – “System.Array.Clone()” and “System.Array.CopyTo()” in C#?

  • “CopyTo()” method can be used to copy the elements of one array to other. 
  • “Clone()” method is used to create a new array to contain all the elements which are in the original array.

Explain circular reference in C#?

This is a situation where in, multiple resources are dependent on each other and this causes a lock condition and this makes the resource to be unused.

List out some of the exceptions in C#?

Below are some of the exceptions in C# -

  • NullReferenceException
  • ArgumentNullException
  • DivideByZeroException
  • IndexOutOfRangeException
  • InvalidOperationException
  • StackOverflowException etc.

Explain Generics in C#?

Generics in c# is used to make the code reusable and which intern decreases the code redundancy and increases the performance and type safety.
Namespace – “System.Collections.Generic” is available in C# and this should be used over “System.Collections” types.

Explain object pool in C#?

  • Object pool is used to track the objects which are being used in the code. So object pool reduces the object creation overhead.
  • Object Pooling is something that tries to keep a pool of objects in memory to be re-used later and hence it will reduce the load of object creation to a great extent. 

What you mean by delegate in C#?

Delegates are type safe pointers unlike function pointers as in C++. Delegate is used to represent the reference of the methods of some return type and parameters.

What are the types of delegates in C#?

Below are the uses of delegates in C# -


  • Single Delegate
  • Multicast Delegate
  • Generic Delegate

What are the three types of Generic delegates in C#?

Below are the three types of generic delegates in C# -

  • Func (The Func delegate defines a method that can be called on arguments and returns a result.)
  • Action (The Action delegate defines a method that can be called on arguments but does not return a result. )
  • Predicate (The Predicate delegate defines a method that can be called on arguments and always returns Boolean type result. )

What are the differences between events and delegates in C#?

Main difference between event and delegate is event will provide one more of encapsulation over delegates. So when you are using events destination will listen to it but delegates are naked, which works in subscriber/destination model.

What are the uses of delegates in C#?
Below are the list of uses of delegates in C# -
  • Callback Mechanism
  • Asynchronous Processing
  • Abstract and Encapsulate method
  • Multicasting
What is Nullable Types in C#?
Variable types does not hold null values so to hold the null values we have to use nullable types. So nullable types can have values either null or other values as well.

Why to use “Nullable Coalescing Operator” (??) in C#?

Nullable Coalescing Operator can be used with reference types and nullable value types. So if the first operand of the expression is null then the value of second operand is assigned to the variable.

Define Multicast Delegate in C#?

A delegate with multiple handlers are called as multicast delegate.

What is enum in C#?

enum keyword is used for declaring an enumeration, which consists of named constants and it is called as enumerator lists. Enums are value types in C# and these can’t be inherited.

Which are the loop types available in C#?

Below are the loop types in C# -

Do.. While