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.
C# interview questions covering types, equality, immutability & internals.
Open a question for the full answer, code and interview guidance.
Reference equality checks whether two reference variables point to the same object instance. Value equality checks whether two objects represent the same logical value.
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.
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.
A readonly struct is a value type whose instance fields must be readonly and whose instance state cannot be modified after construction.
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.
Variance controls how generic types relate when their type arguments have an inheritance relationship.
A generic method declares one or more type parameters independently of whether the containing class is generic.
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.
nameof returns the source-code name of a variable, type, property, method, or other symbol as a string.
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.