Using as : as « Operator « C# / CSharp Tutorial






You can use the as operator to cast without raising an exception if the cast fails.

The general form:

expr as type
  1. expr is the expression being cast to type.
  2. On succeed, a reference to type is returned.
  3. Otherwise, a null reference is returned.
3.13.as
3.13.1.Using as
3.13.2.The As Operator for custom class type
3.13.3.Use the 'as' operator to perform a safe cast
3.13.4.as operator in class hearchy