User x = null;
object o = x;
// determine type with only reference to o
And Generics will NOT Work
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Imagine you have a library of books. Imagine you also have a box of cards, one card for each book. (Younger readers: libraries actually used to have such systems, before computers made them obsolete.)
Now imagine you have two trays. One tray is marked "Science Fiction" and the other tray is marked "Any book".
The SF tray is empty.
You tell your assistant librarian "Dump whatever is in the Any tray, then make a photocopy of whatever is in the SF tray and put the copy in the Any tray."
After dumping the Any tray it becomes empty, and since the SF tray is empty there is nothing to photocopy, therefore the Any tray stays empty.
The analogue of your question is now "what is the genre of the book whose card is in the Any tray?" and the answer is "there is no such genre because the Any tray is empty". It’s not like the fact that the SF tray was empty somehow "infects" the Any tray to make it "empty but SF flavoured".
Does that make sense? Variables are just storage locations; null references are references that mean "this doesn’t reference anything at all", and there is no flavour to "nothing at all".
For more on this distinction see my article on the subject:
https://web.archive.org/web/20100823051812/http://blogs.msdn.com/b/ericlippert/archive/2009/10/29/i-have-a-fit-but-a-lack-of-focus.aspx