13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATION• If either of the delegate instances has an invocation list (§22.1) containing one entry, they are equal ifand only if the other also has an invocation list containing one entry, and either:• Both refer to the same static method, or• Both refer to the same non-static method on the same target object.• If either of the delegate instances has an invocation list containing two or more entries, those instancesare equal if and only if their invocation lists are the same length, and each entry in one’s invocation listis equal to the corresponding entry, in order, in the other’s invocation list.Delegates of different types can be considered equal by the above definition, as long as they have the samereturn type and parameter types.14.9.9 The is operatorThe is operator is used to dynamically check if the run-time type of an object is compatible with a giventype. The result of the operation e is T, where e is an expression and T is a type, is a boolean valueindicating whether e can successfully be converted to type T by a reference conversion, a boxing conversion,or an unboxing conversion. The operation is evaluated as follows:• If the compile-time type of e is the same as T, or if an implicit reference conversion (§13.1.4) or boxingconversion (§13.1.5) exists from the compile-time type of e to T:If e is of a reference type, the result of the operation is equivalent to evaluating e != null.If e is of a value type, the result of the operation is true.• Otherwise, if an explicit reference conversion (§13.2.3) or unboxing conversion (§13.2.4) exists fromthe compile-time type of e to T, a dynamic type check is performed:If the value of e is null, the result is false.Otherwise, let R be the run-time type of the instance referenced by e. If R and T are the same type, if R is areference type and an implicit reference conversion from R to T exists, or if R is a value type and T is aninterface type that is implemented by R, the result is true.Otherwise, the result is false.• Otherwise, no reference or boxing conversion of e to type T is possible, and the result of the operation isfalse.The is operator only considers reference conversions, boxing conversions, and unboxing conversions. Otherconversions, such as user defined conversions, are not considered by the is operator.14.9.10 The as operatorThe as operator is used to explicitly convert a value to a given reference type using a reference conversionor a boxing conversion. Unlike a cast expression (§14.6.6), the as operator never throws an exception.Instead, if the indicated conversion is not possible, the resulting value is null.In an operation of the form e as T, e must be an expression and T must be a reference type. The type of theresult is T, and the result is always classified as a value. The operation is evaluated as follows:• If the compile-time type of e is the same as T, the result is simply the value of e.• Otherwise, if an implicit reference conversion (§13.1.4) or boxing conversion (§13.1.5) exists from thecompile-time type of e to T, this conversion is performed and becomes the result of the operation.• Otherwise, if an explicit reference conversion (§13.2.3) exists from the compile-time type of e to T, adynamic type check is performed:If the value of e is null, the result is the value null with the compile-time type T.168

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!