In this instance, there is no practical difference, and both assignments will compile down to exactly the same MSIL opcodes. However, there is one case where casting a null does make a difference, and that's when calling an overloaded method.
class A { }
class B { }
class C
{
public static void Foo( A value );
public static void Foo( B value );
}
Simply calling C.Foo( null );
is ambiguous, and the compiler can't reason about which you intend to invoke, but if you cast the null first: C.Foo( (A)null );
, it's now clear that you mean to call the first overload, but pass it a null instead of an instance of A
.