How Generics save from Boxing

Total: 6 Average: 3.7

At the method input, we often perform a null test. Someone makes the test as a separate method, so that the code looks cleaner, and gets something like this:

public void ThrowIfNull(object obj)
{
   if(obj == null)
   {
      throw new ArgumentNullException();
   }
}

The interesting thing about this test is that I see a frequent use of the object attribute, though you can use generic. Let’s try to replace our method with generic and compare performance.

Read More