对空传播感到困惑

Confused about null-propagation

我尝试了几种方法,但无法将以下语句转换为空传播。

可能吧,我不知道它是如何工作的。

catch (Exception ex)
{
    if (VGUILogger.Instance != null)
    {
        VGUILogger.Instance.HandleException(ex);
    }
}

你试过了吗?

 VGUILogger.Instance?.HandleException(ex);

https://docs.microsoft.com/en-us/archive/msdn-magazine/2014/october/csharp-the-new-and-improved-csharp-6-0