最快的数据结构,用于检查对象列表中的属性是否匹配

Dot*_*NET 7 .net c# dictionary hashset data-structures

我有一个存储许多对象的列表.每个对象都有一个变量形式的属性.

我希望能够检查此列表中的任何项目是否包含某个属性.类似于Dictionary的ContainsKey方法.这种数据结构要保存极大量的值,甚至可能是数百万,因此我希望使用能够尽快检查属性的数据结构.

字典是这项工作最快的,还是更快的数据结构?

编辑:

这是我想要实现的一个快速,小例子:

Dictionary<string, Person> persons = new Dictionary<string, Person>(); //where string contains the Person's name

bool isPresent = persons.ContainsKey("Matt");
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 7

听起来你基本上只需要HashSet<T>包含所有属性值 - 假设你真的只想知道它是否被包含.

例如:

var allNames = new HashSet<string>(people.Select(person => person.Name));
Run Code Online (Sandbox Code Playgroud)