It seems to me that the is
operator is a bit inconsistent.
bool Test()
{
// Returns false, but should return true.
return null is string
the
null
value
I've quoted this from your question because it seems to get to the heart of the matter. null
isn't a value - it's the absence of a value. The purpose of is
to me seems to be to answer the question:
If I cast
E
toT
, will I successfully get aT
?
Now, while you can cast null
to T
without error, after doing so you don't "have a T
" - you've still got nothing. So it's not the case that null
"is" a T
, so is
returns false.