Advertisement

Latest Post

Thursday, 13 April 2017

What is Difference Between IS and As Operator

I am sharing the difference between IS and As operator with example that is below.

IS - It returns the result as a Boolean (True Or False) . It is used to Check the Compatibility of an Object with a given Type.

Example:-


if (your_Object is StringBuilder)
{

}
else{

}

AS - This is used to Casting of Object to a given Type.

Example:-


StringBuilder obj = your_Object as StringBuilder;
if (obj != null)
{

}
else
{

}

Government Jobs