找出记录缓存键里的 bug

来自 记录类型
C# 14 / .NET 10 进阶 4分钟 找出 1处问题

找出已插入记录键的查找不再可靠的原因。

csharp
using System;
using System.Collections.Generic;

SearchKey key = new("shoes") { Page = 1 };
Dictionary<SearchKey, string> cache = new()
{
    [key] = "result"
};

key.Page = 2;
Console.WriteLine(cache.ContainsKey(key));

public sealed record SearchKey(string Query)
{
    public int Page { get; set; }
}
在试验场中打开
报告错误