Given
HashSet<T> set;
List<T> list;
T t;
其中哪一个对于小型集合表现更好?
if (! list.Contains (t)) list.Add (t);
Or
set.Add (t);
疑点来源:HashSet 与 List 性能对比 https://stackoverflow.com/questions/150750/hashset-vs-list-performance
It really has to do with how you are going to use the data structures. If you need to access an item using an index, then you can't use a HashSet, also if you need to store duplicates, you can;t use HashSet. A List is typically used for most operations, so I you don't understand the underlying design and functionality of the HashSet, then chances are a List will suffice.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)