简体   繁体   English

内部System.Linq.Set <T> vs public System.Collections.Generic.HashSet <T>

[英]Internal System.Linq.Set<T> vs public System.Collections.Generic.HashSet<T>

Check out this piece of code from Linq.Enumerable class: 查看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; 
    }

Why did the guys at Microsoft decided to use this internal implementation of Set and not the regular HashSet ? 为什么Microsoft的人决定使用Set内部实现而不是常规的HashSet If it's better in any way, why not exposing it to the public? 如果它以任何方式更好,为什么不将它暴露给公众?

The implementation of this Set<T> is far simpler than HashSet<T> as it is only needs to add and remove elements and check for existence for LINQ internal processes. 这个Set<T>的实现比HashSet<T>简单得多,因为它只需要添加和删除元素并检查LINQ内部进程是否存在。 It does not implement any interfaces or expose iterators etc. 它没有实现任何接口或暴露迭代器等。

So probably it is faster for the purpose LINQ uses it for. 所以LINQ使用它的目的可能更快。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在视图中得到以下奇怪的文本:System.Collections.Generic.HashSet`1 [automasis.Models.ElencoProvince] System.Collections.Generic.HashSet - I get this strange text on my view : System.Collections.Generic.HashSet`1[automasis.Models.ElencoProvince] System.Collections.Generic.HashSet 无法将带有[]的索引应用于类型&#39;System.Collections.Generic.HashSet的表达式 <string[]> &#39; - Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.HashSet<string[]>' 键入“对象{System.Collections.Generic.List <T> }“ VS” System.Collections.Generic.List <T> ” - Type “object {System.Collections.Generic.List<T>}” VS “System.Collections.Generic.List<T>” System.Collections.Generic.List之间的区别 <T> .ToArray()和System.Linq.Enumerable.ToArray <T> ()? - Difference between System.Collections.Generic.List<T>.ToArray() and System.Linq.Enumerable.ToArray<T>()? 无法隐式转换类型&#39;System.Collections.Generic.List <T> &#39;to&#39;System.Linq.IQueryable <T> “ - Cannot implicitly convert type 'System.Collections.Generic.List<T>' to 'System.Linq.IQueryable<T>' System.Collections.Generic.Find()vs Linq.First() - System.Collections.Generic.Find() vs Linq.First() 在System.Collections.Generic.List中的Find() <T> - Find() In a System.Collections.Generic.List<T> 如何从interface.System.Linq.IQueryable更改var <out T> 对System.Collections.generic.List进行分类 <T> - How to change var from interface.System.Linq.IQueryable<out T> to class System.Collections.generic.List<T> C#:如何比较两个集合(System.Collection.Generic.List <T> )使用Linq / Lambda? - C# : How to compare two collections (System.Collection.Generic.List<T>) using Linq/Lambda? System.Collections.Generic.Dictionary`Add`vs set&#39;Item` - System.Collections.Generic.Dictionary `Add` vs set `Item`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM