C# Miscillaneous Operators

C# Miscillaneous Operators

There are few other important operators including sizeof, typeof and ? : supported by C#.

OperatorDescription
sizeof()Returns the size of a data type.
typeof()Returns the type of a class.
&Returns the address of an variable.
*Pointer to a variable.
? :Conditional Expression
isDetermines whether an object is of a certain type.
asCast without raising an exception if the cast fails.

 

C# Miscillaneous Operators Examples

  • sizeof(): sizeof(int), returns 4.
  • typeof(): typeof(StreamReader);
  • &: &a; returns actual address of the variable.
  • *: *a; creates pointer named 'a' to a variable.
  • ? : If Condition is true ? Then value X : Otherwise value Y
  • is: If( Ford is Car) // checks if Ford is an object of the Car class.
  • as: Object obj = new StringReader("Hello");
    StringReader r = obj as StringReader;