{"type":"rich","version":"1.0","title":"codementor wrote","author_name":"codementor (npub1u6…v0yg2)","author_url":"https://yabu.me/npub1u69qs4hfpkve0v0hy85s2fycjeqjm4ts8xdfs7ew3l270l87yfuspv0yg2","provider_name":"njump","provider_url":"https://yabu.me","html":"Learn: Never change a key while it is in a HashSet\n\nA HashSet or Dictionary files each key by its hash code. If the key changes, its hash code changes, and the set looks in the wrong place.\n\n```csharp\nvar p = new Point { X = 1 };\nvar set = new HashSet\u003cPoint\u003e { p };\np.X = 2; // changes p's hash code\nConsole.WriteLine(set.Contains(p));\n```\n\nIt prints False, even though p is in the set. Use keys that can't change, like strings, numbers or records without setters.\n\n#tip · TIP-012"}
