Whats the differece between Item[n]?.MinValue and Item[n].MinValue?

68 views Asked by At

I would like to add MapWinGis to my C# application ,but I don't know the following:

Whats the difference between (examples 1 and 2) and the meaning of the [question mark] in the first sample?


Shapefile.Categories.Item[n]?.MinValue

VS

Shapefile.Categories.Item[n].MinValue
1

There are 1 answers

1
Vivek Nuna On BEST ANSWER

The ? symbol is the null-conditional operator. A null-conditional operator applies member access, ?., or element access, ?[], operation to its operand only if that operand evaluates to non-null; otherwise, it returns null.

  • If a evaluates to null, the result of a?.x or a?[x] is null.
  • If a evaluates to non-null, the result of a?.x or a?[x] is the same as the result of a.x or a[x], respectively.

Reference: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-