C#中线程安全的HashSet
ConcurrentHashSet
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
官方例子
var concurrentHashSet =
new ConcurrentHashSet<string>(
new[]
{
"hamster",
"HAMster",
"bar",
},
StringComparer.OrdinalIgnoreCase);
concurrentHashSet.TryRemove("foo");
if (concurrentHashSet.Contains("BAR"))
{
Console.WriteLine(concurrentHashSet.Count);
}
内容来源
www.nuget.org/packages/ConcurrentHashSet/