Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp 4 Language Specification.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
2.51 Mб
Скачать

6.1.3Implicit enumeration conversions

An implicit enumeration conversion permits the decimal-integer-literal 0 to be converted to any enum-type and to any nullable-type whose underlying type is an enum-type. In the latter case the conversion is evaluated by converting to the underlying enum-type and wrapping the result (§4.1.10).

6.1.4Implicit nullable conversions

Predefined implicit conversions that operate on non-nullable value types can also be used with nullable forms of those types. For each of the predefined implicit identity and numeric conversions that convert from a non-nullable value type S to a non-nullable value type T, the following implicit nullable conversions exist:

  • An implicit conversion from S? to T?.

  • An implicit conversion from S to T?.

Evaluation of an implicit nullable conversion based on an underlying conversion from S to T proceeds as follows:

  • If the nullable conversion is from S? to T?:

  • If the source value is null (HasValue property is false), the result is the null value of type T?.

  • Otherwise, the conversion is evaluated as an unwrapping from S? to S, followed by the underlying conversion from S to T, followed by a wrapping (§4.1.10) from T to T?.

  • If the nullable conversion is from S to T?, the conversion is evaluated as the underlying conversion from S to T followed by a wrapping from T to T?.

6.1.5Null literal conversions

An implicit conversion exists from the null literal to any nullable type. This conversion produces the null value (§4.1.10) of the given nullable type.

6.1.6Implicit reference conversions

The implicit reference conversions are:

  • From any reference-type to object and dynamic.

  • From any class-type S to any class-type T, provided S is derived from T.

  • From any class-type S to any interface-type T, provided S implements T.

  • From any interface-type S to any interface-type T, provided S is derived from T.

  • From an array-type S with an element type SE to an array-type T with an element type TE, provided all of the following are true:

  • S and T differ only in element type. In other words, S and T have the same number of dimensions.

  • Both SE and TE are reference-types.

  • An implicit reference conversion exists from SE to TE.

  • From any array-type to System.Array and the interfaces it implements.

  • From a single-dimensional array type S[] to System.Collections.Generic.IList<T> and its base interfaces, provided that there is an implicit identity or reference conversion from S to T.

  • From any delegate-type to System.Delegate and the interfaces it implements.

  • From the null literal to any reference-type.

  • From any reference-type to a reference-type T if it has an implicit identity or reference conversion to a reference-type T0 and T0 has an identity conversion to T.

  • From any reference-type to an interface or delegate type T if it has an implicit identity or reference conversion to an interface or delegate type T0 and T0 is variance-convertible (§13.1.3.2) to T.

  • Implicit conversions involving type parameters that are known to be reference types. See §6.1.10 for more details on implicit conversions involving type parameters.

The implicit reference conversions are those conversions between reference-types that can be proven to always succeed, and therefore require no checks at run-time.

Reference conversions, implicit or explicit, never change the referential identity of the object being converted. In other words, while a reference conversion may change the type of the reference, it never changes the type or value of the object being referred to.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]