CLR allows an object to be converted to its actual type or its base type.
In C #, You can implicitly convert an object to its base type. to convert an object to a derived type, you must display the conversion. Example:
Object o = new emplee ();
Emplee E = (emplee) O;
However, if you convert an object to its own derived type, an error is returned:
Object o = new object ();
Emplee E = (emplee) O;
Therefore, CLR is type-safe.
Is as operator usage in C #
In C #, another method of type conversion is to use the is as operator.
Is: checks whether the object is compatible with the specified object and returns the bool type.
Example:
Object o = new object ();
Bool b1 = (O is object); // true
Bool b2 = (O is emplee); // false
Is:
If (O is emplee)
{
Emplee E = (emplee) O;
}
As: aims to simplify isCodeStatement to improve performance. Usage:
Emplee E = O as emplee;
If (E! = NULL)
{}
In this Code, CLR checks whether o is compatible with the emplee type. If compatible, it is converted to the emplee type. If incompatible, null is returned.