![](/img/trans.png)
[英]I get this strange text on my view : System.Collections.Generic.HashSet`1[automasis.Models.ElencoProvince] System.Collections.Generic.HashSet
[英]Internal System.Linq.Set<T> vs public System.Collections.Generic.HashSet<T>
查看Linq.Enumerable
类中的这段代码:
static IEnumerable<TSource> DistinctIterator<TSource>(IEnumerable<TSource> source, IEqualityComparer<TSource> comparer) {
Set<TSource> set = new Set<TSource>(comparer);
foreach (TSource element in source)
if (set.Add(element)) yield return element;
}
为什么Microsoft的人决定使用Set
内部实现而不是常规的HashSet
? 如果它以任何方式更好,为什么不将它暴露给公众?
这个Set<T>
的实现比HashSet<T>
简单得多,因为它只需要添加和删除元素并检查LINQ内部进程是否存在。 它没有实现任何接口或暴露迭代器等。
所以LINQ使用它的目的可能更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.