1

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?

jasonh
  • 29,297
  • 11
  • 59
  • 61

4 Answers4

5

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

mqp
  • 70,359
  • 14
  • 95
  • 123
  • 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. – Dirk Vollmar Jun 12 '09 at 21:44
  • I've voted to close it since it's not really relevant anymore, considering my mistake. – jasonh Jun 12 '09 at 21:45
0

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
  • 44,864
  • 6
  • 88
  • 112
0

You can't statically resolve a null.

Jason Watts
  • 1,086
  • 5
  • 13
0

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

C# get type of null object

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

Community
  • 1
  • 1
Josh
  • 68,005
  • 14
  • 144
  • 156