Generic Comparer

Have you ever had to write a comparer for a specific type, only to be frustrated when you needed to write a second and third comparer for other types? Fear not, a generic comparer can take care of this for you! /// <summary> /// Compares two objects of any type. /// </summary> /// <typeparam name="T">The type to be compared.</typeparam> public class GenericComparer<T> : IComparer<T> { // The compare method private readonly Func<T, T, int> _compareMethod = null; /// <summary> /// The constructor. [Read More]

An Overview of Generic Constraints

This is my first post. I hope that it doesn’t suck. As of .NET 2.0, Microsoft introduced the concept of generics. Generics is a concept that allow you to “template” methods and types such as classes and interfaces in a (generally) type-safe way. Upon compilation, generic type metadata is stored in IL, and JIT’d as you reference the generic method or class with an actual type at runtime. Value types each get their own “copy” of the JIT’d generic code, whereas reference types share a single instance of the code. [Read More]