Relational and Type-Testing Operators

The <, >, <=, >=, =, <>, Is and As operators are named relational and type-testing operators.

relational-expression   <   additive-expression

relational-expression   >   additive-expression

relational-expression   <=   additive-expression

relational-expression   >=   additive-expression

relational-expression   Is   type

relational-expression   As   type

equality-expression:

relational-expression

equality-expression   ==   relational-expression

equality-expression   <>   relational-expression

The Is Operator

The Is operator is used to check if the runtime type of an object is compatible with a given type. The result of the operation E is T, where E is an expression and T is a type, is a logical value indicating whether E can successfully be converted to type T by a reference conversion, a boxing conversion, or an unboxing conversion. The operator is executed as follows:

The As Operator

The As operator is used to explicitly convert a value to a given type. In an operation of the form E As T, E must be an expression and T must be a type. The type of the result is T, and the result is always classified as a value. The operation is executed successfully if an explicit conversion exists from the compile-time type of E to T. Otherwise, System.InvalidCastException is raised.

See also:

Expressions