Заглавная страница Избранные статьи Случайная статья Познавательные статьи Новые добавления Обратная связь FAQ Написать работу КАТЕГОРИИ: АрхеологияБиология Генетика География Информатика История Логика Маркетинг Математика Менеджмент Механика Педагогика Религия Социология Технологии Физика Философия Финансы Химия Экология ТОП 10 на сайте Приготовление дезинфицирующих растворов различной концентрацииТехника нижней прямой подачи мяча. Франко-прусская война (причины и последствия) Организация работы процедурного кабинета Смысловое и механическое запоминание, их место и роль в усвоении знаний Коммуникативные барьеры и пути их преодоления Обработка изделий медицинского назначения многократного применения Образцы текста публицистического стиля Четыре типа изменения баланса Задачи с ответами для Всероссийской олимпиады по праву Мы поможем в написании ваших работ! ЗНАЕТЕ ЛИ ВЫ?
Влияние общества на человека
Приготовление дезинфицирующих растворов различной концентрации Практические работы по географии для 6 класса Организация работы процедурного кабинета Изменения в неживой природе осенью Уборка процедурного кабинета Сольфеджио. Все правила по сольфеджио Балочные системы. Определение реакций опор и моментов защемления |
The null coalescing operatorСодержание книги
Поиск на нашем сайте
The?? operator is called the null coalescing operator. null-coalescing-expression: A null coalescing expression of the form a?? b requires a to be of a nullable type or reference type. If a is non-null, the result of a?? b is a; otherwise, the result is b. The operation evaluates b only if a is null. The null coalescing operator is right-associative, meaning that operations are grouped from right to left. For example, an expression of the form a?? b?? c is evaluated as a?? (b?? c). In general terms, an expression of the form E1?? E2??...?? EN returns the first of the operands that is non-null, or null if all operands are null. The type of the expression a?? b depends on which implicit conversions are available on the operands. In order of preference, the type of a?? b is A0, A, or B, where A is the type of a (provided that a has a type), B is the type of b (provided that b has a type), and A0 is the underlying type of A if A is a nullable type, or A otherwise. Specifically, a?? b is processed as follows: · If A exists and is not a nullable type or a reference type, a compile-time error occurs. · If b is a dynamic expression, the result type is dynamic. At run-time, a is first evaluated. If a is not null, a is converted to dynamic, and this becomes the result. Otherwise, b is evaluated, and this becomes the result. · Otherwise, if A exists and is a nullable type and an implicit conversion exists from b to A0, the result type is A0. At run-time, a is first evaluated. If a is not null, a is unwrapped to type A0, and this becomes the result. Otherwise, b is evaluated and converted to type A0, and this becomes the result. · Otherwise, if A exists and an implicit conversion exists from b to A, the result type is A. At run-time, a is first evaluated. If a is not null, a becomes the result. Otherwise, b is evaluated and converted to type A, and this becomes the result. · Otherwise, if b has a type B and an implicit conversion exists from a to B, the result type is B. At run-time, a is first evaluated. If a is not null, a is unwrapped to type A0 (if A exists and is nullable) and converted to type B, and this becomes the result. Otherwise, b is evaluated and becomes the result. · Otherwise, a and b are incompatible, and a compile-time error occurs. Conditional operator The?: operator is called the conditional operator. It is at times also called the ternary operator. conditional-expression: A conditional expression of the form b? x: y first evaluates the condition b. Then, if b is true, x is evaluated and becomes the result of the operation. Otherwise, y is evaluated and becomes the result of the operation. A conditional expression never evaluates both x and y. The conditional operator is right-associative, meaning that operations are grouped from right to left. For example, an expression of the form a? b: c? d: e is evaluated as a? b: (c? d: e). The first operand of the?: operator must be an expression that can be implicitly converted to bool, or an expression of a type that implements operator true. If neither of these requirements is satisfied, a compile-time error occurs. The second and third operands, x and y, of the?: operator control the type of the conditional expression. · If x has type X and y has type Y then o If an implicit conversion (§6.1) exists from X to Y, but not from Y to X, then Y is the type of the conditional expression. o If an implicit conversion (§6.1) exists from Y to X, but not from X to Y, then X is the type of the conditional expression. o Otherwise, no expression type can be determined, and a compile-time error occurs. · If only one of x and y has a type, and both x and y, of areimplicitly convertible to that type, then that is the type of the conditional expression. · Otherwise, no expression type can be determined, and a compile-time error occurs. The run-time processing of a conditional expression of the form b? x: y consists of the following steps: · First, b is evaluated, and the bool value of b is determined: o If an implicit conversion from the type of b to bool exists, then this implicit conversion is performed to produce a bool value. o Otherwise, the operator true defined by the type of b is invoked to produce a bool value. · If the bool value produced by the step above is true, then x is evaluated and converted to the type of the conditional expression, and this becomes the result of the conditional expression. · Otherwise, y is evaluated and converted to the type of the conditional expression, and this becomes the result of the conditional expression.
|
||||
Последнее изменение этой страницы: 2016-12-14; просмотров: 392; Нарушение авторского права страницы; Мы поможем в написании вашей работы! infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 3.140.198.3 (0.006 с.) |