CKTIS / C#
System.Collections.Frozen.FrozenSet: practical reference
System.Collections.Frozen.FrozenSet: practical reference: FrozenSet<T> is an immutable set optimized for repeated Contains checks after construction is complete.
Version: .NET 8+; verified on .NET 10.0.14
Syntax
System.Collections.Frozen.FrozenSet /* select a documented member or constructor */FrozenSet is an immutable set optimized for repeated Contains checks after construction is complete.
Use it for stable allowlists, keyword sets, or other membership data queried many times.
The comparer is fixed and preparation has a cost that can outweigh the benefit for small or short-lived sets.
Construction removes duplicates, while mutating an object used as a key can violate its stored hash assumptions.
The complete program actually uses System.Collections.Frozen.FrozenSet; its exact expected stdout is True.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var set = new[] { "a", "b" }.ToFrozenSet();
Console.WriteLine(set.Contains("b"));
Result
True
The complete program actually uses `System.Collections.Frozen.FrozenSet`; its exact expected stdout is `True`.