mursaleen fayyaz

mursaleen fayyaz

  • NA
  • 84
  • 125.2k

Type Information Operators

Jun 3 2013 1:25 PM
is , as , typeof , sizeof

The is Operator allow you to check whether an object is compatible with a specified type.

int i = 10;
if(i is object)
{
        Console.WriteLine("i is an object");
}

The as Operator is used to perform explicit type conversions of reference types. If the type being converted is compatible with the specified type, conversion is performed successfully. However, if the types are incompatible, the as operator returns the value null.

object o1 = "Some string";
object o2 = 5;

string s1 = o1 as string;        //successful conversion
string s2 = o2 as string;        //null

The sizeof Operator

Console.WriteLine(sizeof(int));

with Complex types:

unsafe
{
        Console.WriteLine(sizeof(Customer));
}

The typeof operator returns a System.Type object representing a specified type.

typeof(string) will return a Type object representing the System.String type.





Thanks for Viewing. Comments are appreciated.