0

To test if an object is of a certain type then we write if ( myObject is SomeClassName )

But how do we write if I want to test that the object is not of the mentionned type ?

pheromix
  • 18,213
  • 29
  • 88
  • 158

2 Answers2

1

There isn't one, you have to wrap it in a ! operator:

if (!(myObject is SomeClassName))
Jonas Høgh
  • 10,358
  • 1
  • 26
  • 46
1
if (!(myObject is SomeClassName))

Is probably the cleanest way of checking not is. Just checks if it is the type of object then flips it.

Tom Dee
  • 2,516
  • 4
  • 17
  • 25