You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A *null_conditional_member_access* expression `E` is of the form `P?.A`. Let `T` be the type of the expression `P.A`. The meaning of `E` is determined as follows:
1760
+
A *null_conditional_member_access* expression `E` is of the form `P?.A`. The meaning of `E` is determined as follows:
1761
1761
1762
-
- If `T` is a type parameter that is not known to be a reference type or a non-nullable value type, a compile-time error occurs.
1763
-
- If `T` is a non-nullable value type, then the type of `E` is `T?`, and the meaning of `E` is the same as the meaning of:
1762
+
- If the type of `P` is a nullable value type:
1764
1763
1765
-
```csharp
1766
-
((object)P==null) ? (T?)null:P.A
1767
-
```
1764
+
Let `T` be the type of `P.GetValueOrDefault().A`.
1768
1765
1769
-
Except that `P` is evaluated only once.
1770
-
- Otherwise the type of `E` is `T`, and the meaning of `E` is the same as the meaning of:
1766
+
- If `T` is a type parameter that is not known to be a reference type or a non-nullable value type, a compile-time error occurs.
1767
+
- If `T` is a non-nullable value type, then the type of `E` is `T?`, and the meaning of `E` is the same as the meaning of:
A *null_conditional_element_access* is a conditional version of *element_access* ([§12.8.11](expressions.md#12811-element-access)) and it is a binding time error if the result type is `void`. For a null conditional expression where the result type may be `void` see ([§12.8.10](expressions.md#12810-null-conditional-invocation-expression)).
2098
2122
2099
-
A *null_conditional_element_access* expression `E` is of the form `P?[A]B`; where `B` are the *dependent_access*es, if any. Let `T` be the type of the expression `P[A]B`. The meaning of `E` is determined as follows:
2123
+
A *null_conditional_element_access* expression `E` is of the form `P?[A]B`; where `B` are the *dependent_access*es, if any. The meaning of `E` is determined as follows:
2100
2124
2101
-
- If `T` is a type parameter that is not known to be a reference type or a non-nullable value type, a compile-time error occurs.
2102
-
- If `T` is a non-nullable value type, then the type of `E` is `T?`, and the meaning of `E` is the same as the meaning of:
2125
+
- If the type of `P` is a nullable value type:
2103
2126
2104
-
```csharp
2105
-
((object)P==null) ? (T?)null:P[A]B
2106
-
```
2127
+
Let `T` be the type of the expression `P.GetValueOrDefault()[A]B`.
2128
+
2129
+
- If `T` is a type parameter that is not known to be a reference type or a non-nullable value type, a compile-time error occurs.
2130
+
- If `T` is a non-nullable value type, then the type of `E` is `T?`, and the meaning of `E` is the same as the meaning of:
2107
2131
2108
-
Except that `P` is evaluated only once.
2109
-
- Otherwise the type of `E` is `T`, and the meaning of `E` is the same as the meaning of:
0 commit comments