2

Null coalescing allows for some cleaner syntax in many cases.

But I just ran into the following when trying to unsubscribe from an event:

consumer?.Received -= Consumer_Received;

For which VS tells me:

The event 'EventingBasicConsumer.Received' can only appear on the left hand side of += or -=

So, it seems I have to resort to the uglier:

if(consumer != null) consumer.Received -= Consumer_Received

Or is there some other, clean, alternative?

Learner
  • 97
  • 10

0 Answers0