c# - can we replace IS operator with some other operators -
can replace is
operator functionality other operators or functions or other except as? have tried replace this
class test { program = new program(); programtwo b = new programtwo(); if(a.gettype()?. == b.gettype()) console.writeline("true"); }
but not working case of derived object checking base class 1 please me how solve this?
i don't understand why don't want use is
. wayyyy more beautiful. code clearer if use is
.
an alternative isassignablefrom
. (docs)
console.writeline(typeof(object).isassignablefrom (5.gettype()));
a second alternative isinstanceoftype
. (docs)
console.writeline(typeof(object).isinstanceoftype(5));
the above 2 similar to
console.writeline(5 object);
see difference between readability?
Comments
Post a Comment