yoklainterview sim

Backend Csharp Generics Interfaces Interview Questions

75 verified Backend Csharp Generics Interfaces interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Csharp Generics InterfacesDifficulty 1
public class Box<T>
{
    public T Value { get; set; }
}

var box = new Box<int>();
box.Value = 42;

What is the compile-time type of box.Value?
  • aobject
  • bdynamic
  • cint
  • dT
Explanation:When Box<T> is closed with int (i.e. Box<int>), every occurrence of T inside the type is replaced by int, so box.Value has the concrete compile-time type int, not the open type parameter T.
Csharp Generics InterfacesDifficulty 1
In C#, generic type parameters are reified at runtime. What does this mean compared to Java's type erasure?
  • aThe runtime has no knowledge of T once compiled — same as Java.
  • bThe actual type argument used is known at runtime, so typeof(T) returns the real type.
  • cOnly value type arguments are preserved; reference type arguments are erased.
  • dReification only applies to generic interfaces, not generic classes.
Explanation:Unlike Java, where generic type information is erased at compile time, the CLR keeps full type information for generics at runtime (reification). This is why typeof(T) and reflection over generic types work correctly in C#, for both value and reference type arguments.
Csharp Generics InterfacesDifficulty 1
Func<int, int, int> add = (a, b) => a + b;
Console.WriteLine(add(3, 4));

What is the output?
  • a34
  • bcompile error
  • c7
  • d12
Explanation:Func<int, int, int> is a generic delegate taking two int parameters and returning an int. The lambda adds its two arguments, so add(3, 4) returns 3 + 4 = 7.
Csharp Generics InterfacesDifficulty 1
Action<string> greet = name => Console.WriteLine($"Hello, {name}");
greet("Ada");

What is the output?
  • aHello, {name}
  • bnothing is printed
  • ccompile error
  • dHello, Ada
Explanation:Action<string> is a generic delegate that takes a string argument and returns nothing. Calling greet("Ada") runs the lambda with name = "Ada", printing the interpolated string Hello, Ada.
Csharp Generics InterfacesDifficulty 1
public static void PrintType<T>(T value)
{
    Console.WriteLine(typeof(T).Name);
}

PrintType(42);
PrintType("hello");

What is the output?
  • aInt32
    Int32
  • bT
    T
  • cobject
    object
  • dInt32
    String
Explanation:The compiler infers T from each call's argument type: 42 makes T = int (Int32), "hello" makes T = string (String). typeof(T).Name reflects the actual inferred type for each call, not a generic placeholder like T or object.
Csharp Generics InterfacesDifficulty 1
How is an extension method declared in C#?
  • aAs a static method in a static class, with this before the first parameter.
  • bAs a virtual instance method inside the class it extends.
  • cAs a method decorated with the [Extension] attribute in any class.
  • dAs a partial method added to the original class definition.
Explanation:Extension methods must be static methods defined in a static class; the this modifier on the first parameter tells the compiler which type is being extended, allowing the method to be called as if it were an instance method on that type.

Test yourself against the 3300-question Backend bank.

Start interview