ref*_*med 41 c# lookup dictionary
我需要一种能够插入条目的数据类型,然后能够快速确定是否已插入条目.A Dictionary
似乎适合这种需要(见例).但是,我对字典没用values
.我还应该使用字典还是有其他更适合的数据类型?
public class Foo
{
private Dictionary<string, bool> Entities;
...
public void AddEntity(string bar)
{
if (!Entities.ContainsKey(bar))
{
// bool value true here has no use and is just a placeholder
Entities.Add(bar, true);
}
}
public string[] GetEntities()
{
return Entities.Keys.ToArray();
}
}
Run Code Online (Sandbox Code Playgroud)
Hab*_*bib 84
你可以用HashSet<T>
.
本
HashSet<T>
类提供高性能的设置操作.集合是一个不包含重复元素的集合,其元素没有特定的顺序.
归档时间: |
|
查看次数: |
2738 次 |
最近记录: |