Alex Rivera | Logout

What's the opposite of "is"?

Asked 2009-08-27T22:47:01.040
18
if(myVariable is SomeType)

Out of nothing but curiosity, what's the opposite of that? I want to do something like:

if(!myVariable is SomeType)
if(myVariable is not SomeType)

Neither compile.

Given that "is" is a non-searchable word in most engines, this has been a hard one to find an answer to.

Duplicate:

C# : ‘is’ keyword and checking for Not

c#
Edit
Report

1 Answer

4

Jay and marc have the jist of it. Alternatively, you could do:

var cast = myVariable as SomeType;
if(cast == null)
{
  // myVariable is not SomeType
}

The benefit of this method is that you now have a variable already cast as SomeType immediately available for use.

answered 2009-08-27T22:51:04.370

Your Answer