If we cast some null variable to a type, I expect the compiler to throw some exception, but it doesn't. Why?
I mean
string sample1 = null as string;
string sample2 = (string)null;
object t1 = null;
TestClass t2 = (TestClass)t1;
maybe in the first one, the as
operator handles the exception handling. But the others examples must throw exception. How does the compiler handle these situations? Maybe since the variables are null, it does not perform a cast operation? Cause if it really casts a null pointer, it must be an error.