Does null
have a type? How is a null value represented internally? What is happening in the following code?
void Foo(string bar) {...}
void Foo(object bar) {...}
Foo((string)null);
Edit: The answers so far have been unspecific and too high-level. I understand that a reference type object consists of a pointer on the stack which points to a location on the heap which contains a sync block index, a type handle and the object's fields. When I set an instance of an object to null
, where does the pointer on the stack point to, exactly? And in the code snippet, is the cast simply used by the C# compiler to decide which overload to call, and there is not really any casting of null going on?
I am looking for an in-depth answer by someone who understands the CLR internals.