views:

108

answers:

4

The MSDN documentation for the is keyword says:

expression is not null

Why? If MethodThatReturnsNull() is type were called shouldn't that return false since null certainly isn't that type?

A: 

The only thing you can say for certain about null is that you don't know what it is. Comparing something to null generally has a result of null ...

Q: Does 1 == "I don't know"? A: "I dont know"

Check out this blog post by Eric Lippert.

JP Alioto
A: 

You can't statically resolve a null.

Jason Watts
+3  A: 

It does return false if expression is null. Perhaps you're misunderstanding the documentation?

mquander
Correct. MSDN states "An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown." So it is false if expression is null.
0xA3
You're right, I misread the documentation.
jasonh
I've voted to close it since it's not really relevant anymore, considering my mistake.
jasonh
A: 

This was a pretty popular answer I gave to a similar question.

http://stackoverflow.com/questions/930147/c-get-type-of-null-object/930155#930155

That's like asking what kind of cake would have been in an empty box with no label.

Josh Einstein
According to the C# compiler and .NET framework, it's not a <i>type</i> cake. :)
jasonh