草庐IT

IOrderedEnumerable

全部标签

c# - IOrderedEnumerable.Select() 会保留元素顺序吗?

在C#中,使用Select()投影IOrderedEnumerable的元素是否会保留元素顺序?如果是这样,它为什么会返回一个IEnumerable,而不是一个IOrderedEnumerable?如果没有,我该如何实现(除了使用foreach)?请注意,此问题不是thisone的重复问题-我只有一个Select()子句,没有Distinct()。编辑是的,它是LINQtoObjects。顺便说一句,如果我实际上是在查询一些SQLDB,答案会有什么不同吗? 最佳答案 Select不改变元素顺序。这是一个streamingoperat

c# - 如何创建一个空的 IOrderedEnumerable<DynamicNode> 和 IEnumerable<IGrouping<string, DynamicNode>>

我需要一种方法来创建一个空的IOrderedEnumerable和IEnumerable>//以上IGroupingDynamicNode被stackoverflow剥离:(原因:我创建了3个空列表类型(IOrdered、IGrouping、IEnumerable),然后基于一些其他信息(用户指定的选项,例如按创建日期排序或按月分组),然后调用一个函数来分配一个列表属于上述类型。(简短片段)//DOESNTWORKTHISISTHEPARTINEEDIEnumerablebaseList=Enumerable.Empty();IOrderedEnumerableorderedList=

c# - 为什么 List<T> 不实现 IOrderedEnumerable<T>?

我想使用有序的枚举,并使用接口(interface)作为返回类型而不是具体类型。我需要返回一组有序的对象。但是,当使用IList时执行我不能返回IOrderedEnumerable,作为IList不继承IOrderedEnumerable。在下面的示例中,我有一个带有系列存储库的View模型,实现为List。系列对象,因为它们位于List中。,下令。我是一个访问器方法,我想返回经过过滤的系列集合,其中仅返回特定类型的系列对象,同时保持过滤元素之间的原始顺序。//////Representstheviewmodelforthismodule.///publicclassViewModel

C#:如何实现 IOrderedEnumerable<T>

我想实现一些不同的算法来练习,只是为了看看我到底有多糟糕,然后变得更好:p无论如何,我想我会尝试使用IEnumerable和IOrderedEnumerable和其他.Net集合类型只是为了兼容(这样我写的东西以后可以更容易地使用)。但我找不到返回IOrderedEnumerable实例的方法除了使用OrderBy和ThenBy扩展方法。所以我想我必须创建自己的类来实现这个接口(interface)。但老实说,这个界面对我来说不太有意义。可能是,但我不确定。我创建了一个空类,添加了接口(interface),然后让ReSharper为我添加空实现。它看起来像这样:classMyOrde

c# - 是否可以在不使用 OrderBy 的情况下将 IEnumerable 转换为 IOrderedEnumerable?

假设有一个扩展方法可以根据SortMethod枚举指定的几种排序类型(即按各种属性排序)对IQueryable进行排序。publicstaticIOrderedEnumerableOrderByX(thisIQueryablevalues,SortMethod?sortMethod){IOrderedEnumerablequeryRes=null;switch(sortMethod){caseSortMethod.Method1:queryRes=values.OrderBy(a=>a.Property1);break;caseSortMethod.Method2:queryRes=v

c# - 是否可以在不使用 OrderBy 的情况下将 IEnumerable 转换为 IOrderedEnumerable?

假设有一个扩展方法可以根据SortMethod枚举指定的几种排序类型(即按各种属性排序)对IQueryable进行排序。publicstaticIOrderedEnumerableOrderByX(thisIQueryablevalues,SortMethod?sortMethod){IOrderedEnumerablequeryRes=null;switch(sortMethod){caseSortMethod.Method1:queryRes=values.OrderBy(a=>a.Property1);break;caseSortMethod.Method2:queryRes=v

c# - 将 IOrderedEnumerable<KeyValuePair<string, int>> 转换为 Dictionary<string, int>

这个问题在这里已经有了答案:RecreatingaDictionaryfromanIEnumerable>(2个答案)关闭11个月前。我正在关注answertoanotherquestion,我得到了://itemCounterisaDictionary,andIonlywanttokeep//key/valuepairswiththetopmaxAllowedvaluesif(itemCounter.Count>maxAllowed){IEnumerable>sortedDict=fromentryinitemCounterorderbyentry.Valuedescendingse

c# - 为什么返回 IOrderedEnumerable<T> 的 OrderBy 比 Sort 快得多?

这是对这个优秀问题的跟进C#SortandOrderBycomparison.我将使用相同的示例:Listpersons=newList();persons.Add(newPerson("P005","Janson"));persons.Add(newPerson("P002","Aravind"));persons.Add(newPerson("P007","Kazhal"));争论的方法是:persons.Sort((p1,p2)=>string.Compare(p1.Name,p2.Name,true));//andpersons.OrderBy(n=>n.Name);首先让我说

c# - 什么时候返回 IOrderedEnumerable?

是否应该将IOrderedEnumerable用作纯粹用于语义值的返回类型?例如,在表示层消费模型时,我们如何知道集合是需要排序还是已经排序?如果存储库使用ORDERBY子句包装存储过程,情况会怎样。存储库应该返回IOrderedEnumerable吗?如何实现? 最佳答案 我认为这不是个好主意:ShouldIOrderedEnumerablebeusedasareturntypepurelyforsemanticvalue?Forexample,whenconsumingamodelinthepresentationlayer,h
12