Описание тега null-conditional-operator
A Safe navigation operator which is used to test for null before performing a member access (?.) or index (?[]) operation.
A Safe navigation operator used to test for null before performing a member access (?.
) or index (?[]
) operation.
These operators help you write less code to handle null checks, especially for descending into data structures.
C#:
int? length = customers?.Length; // null if customers is null
Customer first = customers?[0]; // null if customers is null
int? count = customers?[0]?.Orders?.Count(); // null if customers, the first customer, or Orders is null
VB:
Dim length = customers?.Length ‘’ null if customers is null
Dim first as Customer = customers?(0); ‘’ null if customers is null
Dim count as Integer? = customers?[0]?.Orders?.Count(); // null if customers, the first customer, or Orders is null
MSDN.