is Keyword VS as Keyword
is
The
is
operator checks if an object can be cast to a specific type.
Example:
if (someObject is StringBuilder) ...
as
The
as
operator attempts to cast an object to a specific type, and returns null if it fails.
Example:
StringBuilder b = someObject as StringBuilder;
if (b != null) ...
as Operator :
The AS operator also checks whether the type of an given object is compatible with the new object type. This keyword will checks whether the type of an given object is compatible with the new object type. If its not compatible with new one then it will return NULL.
object o = "somestring";
string str = o as string;
is Operator:
This Operator will checks weather type of an object is compatible with the new object. If its compatible it returns true otherwise false.
object ocust = new Customer();
if (ocust is Customer)
{
No comments:
Post a Comment