0

How exactly is null conditional operator expaned in C# 6? Could someone explain it as it is Curious C# using statement expansion expanded in the question?

The description from MSDN is as follows:

If one operation in a chain of conditional member access and index operation returns null, then the rest of the chain’s execution stops.

Few working examples:

a) int count = aClassInstance?.PropertyCollection?.Count ?? 0;
b) if (aClassInstance?.PropertyCollection?.Count > 0)
c) aClassInstance?.Dispose();
d) if (aClassInstance?.PropertyCollection?[0]?.Foo == "bar")
Community
  • 1
  • 1
piotrwest
  • 2,098
  • 23
  • 35
  • `myEvent?.Invoke(this, new EventArgs())` will access `myEvent` only once. – Gabriel Nov 22 '16 at 12:50
  • 1
    Thanks for linking the duplicate, I haven't found it. @Gabriel, I'll made another, separated question about those two cases. – piotrwest Nov 22 '16 at 13:04

0 Answers0