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
Dimlength=customers?.Length' null if customers is null
40
+
DimfirstasCustomer=customers?(0)' null if customers is null
41
+
DimcountasInteger?=customers?(0)?.Orders?.Count()' null if customers, the first customer, or Orders is null
44
42
```
45
43
46
44
The last example demonstrates that the null-condition operators are short-circuiting. If one operation in a chain of conditional member access and index operation returns null, then the rest of the chain’s execution stops. Other operations with lower precedence in the expression continue. For example, `E` in the following always executes, and the `??` and `==` operations execute.
47
45
48
-
```vb-c#
46
+
```csharp
49
47
A?.B?.C?[0] ??E
50
48
A?.B?.C?[0] ==E
51
-
49
+
```
50
+
51
+
```vb
52
+
A?.B?.C?(0)??E
53
+
A?.B?.C?(0)==E
52
54
```
53
55
54
56
Another use for the null-condition member access is invoking delegates in a thread-safe way with much less code. The old way requires code like the following:
The new way is thread-safe because the compiler generates code to evaluate `PropertyChanged` one time only, keeping the result in a temporary variable.
78
81
79
82
You need to explicitly call the `Invoke` method because there is no null-conditional delegate invocation syntax `PropertyChanged?(e)`. There were too many ambiguous parsing situations to allow it.
0 commit comments