是的HashSet< T>最快的容器来查找吗?是的、容器、最快、LT

2023-09-03 11:28:30 作者:江湖皆过往

我需要检查特定的字符串包含了一系列其他的:

I need to check that specific string contains in the set of others:

private bool Contains(string field)
{
   return this.Fields.Contains(field); // HashSet<string> local property
}

什么是容器的最佳类型使用,如果只有一个任务呢? - 把若干个字符串,并检查是否另一个是进入或不

What is the best type of container to use if only one task of it - to hold a number of strings and check does another one is into or does not?

推荐答案

是的,HashSet的是为这个完美的,因为它包含一个值来查找不像字典,需要一个键和一个值。

Yes, HashSet is perfect for this since it contains one value to look up unlike a Dictionary which requires a key and a value.

 
精彩推荐
图片推荐