Is

Checks if an object is compatible with a given type and always returns a boolean value
An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.
You can use the Is operator to test whether a cast can be made successfully


The is operator cannot be overloaded.


If you know the specific base class, then just use the is keyword:
This is a cast parameter ?


string myobject = ""; 

If (myobject is string)
{
}
If (myobject is int)
{
}
If (myobject is class1)
{
}

Note that the is operator only considers reference conversions, boxing conversions, and unboxing conversions. Other conversions, such as user-defined conversions, are not considered.


The Is Operator only returns a boolean value
It can be useful when you want to determine the type but not necessarily cast


You can use the Is and As operators to test whether a cast can be made successfully.


class Dog : Animal {} 

void UseIsOperator(Animal a)
if (a is Dog)
{
}




© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext