Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is the "is" operator just syntactic sugar for the "IsInstanceOfType" method

Are the following code snippets equivalent?

class a
{}

class b:a
{}

b foo=new b();

//here it comes

foo is a

//...is the same as...

typeof(a).isinstanceoftype(foo)

Or maybe one of the other Type Methods map closer to the is operator. e.g. "IsAssignableFrom" or "IsSubclassOf"

like image 624
rudimenter Avatar asked Sep 05 '10 20:09

rudimenter


2 Answers

It isn't, because is is tolerant to null reference at the left-hand side.

like image 56
Ondrej Tucny Avatar answered Oct 05 '22 23:10

Ondrej Tucny


It's not the same as is is translated into the isinst opcode whereas IsInstanceOf is a normal virtual call on Type.

like image 25
Just another metaprogrammer Avatar answered Oct 05 '22 22:10

Just another metaprogrammer