Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specification 14 Expressions 14.9 Relational and type-testing operators 14.9.9 The is operator
Paragraph 11 The is operator is used to dynamically check if the run-time type of an object is compatible with a given type. 2 The result of the operation e is T, where e is an expression and T is a type, is a boolean value indicating whether e can successfully be converted to type T by a reference conversion, a boxing conversion, or an unboxing conversion. 3 The operation is evaluated as follows:
Paragraph 21 Note that the is operator only considers reference conversions, boxing conversions, and unboxing conversions. 2 Other conversions, such as user defined conversions, are not considered by the is operator.
- 4 If the compile-time type of e is the same as T, or if an implicit reference conversion (§13.1.4) or boxing conversion (§13.1.5) exists from the compile-time type of e to T:
- 5 If e is of a reference type, the result of the operation is equivalent to evaluating e != null.
- 6 If e is of a value type, the result of the operation is true.
- 7 Otherwise, if an explicit reference conversion (§13.2.3) or unboxing conversion (§13.2.4) exists from the compile-time type of e to T, a dynamic type check is performed:
- 8 If the value of e is null, the result is false.
- 9 Otherwise, let R be the run-time type of the instance referenced by e. 10 If R and T are the same type, if R is a reference type and an implicit reference conversion from R to T exists, or if R is a value type and T is an interface type that is implemented by R, the result is true.
- 11 Otherwise, the result is false.
- 12 Otherwise, no reference or boxing conversion of e to type T is possible, and the result of the operation is false.
|Jagger Software Ltd|
|Company # 4070126|
|VAT # 762 5213 42|