The above code uses T“s implementation of Object.Equals(), which is defined as:

publicvirtualbool Equals(Object obj);

If T is a value type, it will be automatically boxed by the compiler, which has a slight performance cost. However, if you knew that T implemented IEquatable, then you could avoid the boxing entirely. For example, this code would be slightly better performing than the above for value types:

Steven Engelhardt is a Director of Engineering at Relativity, an Adjust Professor of Software Engineering at DePaul University, an avid board gamer, and a father of two. His interests include high-performance data processing systems, server-side and cloud systems architecture, and the Chicago Blackhawks.