Why cast null before checking if object is equal to null?

Posted by jacerhea on Stack Overflow See other posts from Stack Overflow or by jacerhea
Published on 2010-05-23T04:09:53Z Indexed on 2010/05/23 4:10 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

I was looking through the "Domain Oriented N-Layered .NET 4.0 Sample App" project and ran across some code that I do not understand. In this project they often use syntax like the following to check arguments for null:

public GenericRepository(IQueryableContext context,ITraceManager traceManager)
{
    if (context == (IQueryableContext)null)
            throw new ArgumentNullException("context", Resources.Messages.exception_ContainerCannotBeNull);

Why would you cast null to the type of the object you are checking for null?

© Stack Overflow or respective owner

Related posts about c#

Related posts about best-practices