Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the opposite of "is"?

Tags:

c#

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

like image 349
Deane Avatar asked Aug 27 '09 22:08

Deane


People also ask

What is opposite word of is?

▲ Opposite of to be or perform the function of. is not. isn't. ain't.

What is the opposite of not is?

'So' is the opposite of not.

What is the opposite of negative 4?

If you start with negative four, its opposite is going to be positive four. One way to think about it, it's going to have the same absolute value but have a different sign.


2 Answers

Try

if (!(myVariable is SomeType))
like image 195
Jay Riggs Avatar answered Sep 20 '22 16:09

Jay Riggs


You need to surround the statement in parentheses.

if ( !myVariable is SomeType )

That line applies the NOT operator to myVariable, not the entire statement. Try:

if ( !( myVariable is SomeType ) )

Although, I would be wary of code that checks an object for its type anyhow. You may want to look into the concept of polymorphism.

like image 45
Ed S. Avatar answered Sep 20 '22 16:09

Ed S.