找出仪表板订阅里的bug

来自事件订阅与生命周期
C# 14 / .NET 10 进阶 4分钟 找出1处问题

找出为什么调用Disconnect后,这个面板仍会收到更新。

csharp
public sealed class Dashboard
{
    private readonly PriceFeed _feed;

    public Dashboard(PriceFeed feed)
    {
        _feed = feed;
        _feed.Changed += (_, price) => Show(price);
    }

    public void Disconnect()
    {
        _feed.Changed -= (_, price) => Show(price);
    }

    private void Show(decimal price) { }
}
在试验场中打开
报告错误