标签: c# .net events event-handling
在许多情况下,空合并可以使语法更简洁。
但是在尝试退订事件时,我遇到了以下问题:
consumer?.Received -= Consumer_Received;
VS告诉我的
“ EventingBasicConsumer.Received”事件只能出现在+ =或-= 的左侧
“ EventingBasicConsumer.Received”事件只能出现在+ =或-=
因此,看来我不得不求助于丑陋的人:
if(consumer != null) consumer.Received -= Consumer_Received
或者还有其他一些干净的替代方法吗?