C# Interview

Types, Equality, Immutability & Internals

C# interview questions covering types, equality, immutability & internals.

10 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

10 Results
101
SeniorAdvanced

What is the difference between reference equality and value equality in C#?

Reference equality checks whether two reference variables point to the same object instance. Value equality checks whether two objects represent the same logical value.

102
SeniorAdvanced

What is IEquatable<T>, and when should it be implemented?

IEquatable<T> defines a strongly typed Equals(T?) method for value equality. It avoids relying only on object.Equals and can reduce boxing for value types.

103
SeniorAdvanced

What is immutability in C#?

An immutable object cannot have its observable state changed after creation. Instead of modifying an existing object, code creates a new value representing the changed state.

104
SeniorAdvanced

What is a readonly struct?

A readonly struct is a value type whose instance fields must be readonly and whose instance state cannot be modified after construction.

105
SeniorAdvanced

What is the difference between shallow copy and deep copy?

A shallow copy creates a new outer object but copies references to nested reference-type objects. Therefore, the original and copy may still share child objects.

106
SeniorAdvanced

What is covariance and contravariance in C# generics?

Variance controls how generic types relate when their type arguments have an inheritance relationship.

107
SeniorAdvanced

What is a generic method, and how does type inference work?

A generic method declares one or more type parameters independently of whether the containing class is generic.

108
SeniorAdvanced

What is the default keyword in C#?

The default keyword produces the default value of a type. For numeric value types it is zero, for bool it is false, and for reference types it is null.

109
SeniorAdvanced

What is nameof in C#, and why is it useful?

nameof returns the source-code name of a variable, type, property, method, or other symbol as a string.

110
SeniorAdvanced

What is the difference between typeof, GetType(), and is?

typeof obtains a Type object for a type known at compile time. GetType() obtains the actual runtime type of an object instance. The is operator tests whether an object is compatible with a specified type or pattern.