iorderedenumerable

Sorting with OrderBy, ThenBy

天涯浪子 提交于 2020-04-14 06:24:29
问题 I'm trying to sort several columns of a table depending of the previous sorted column. It works fine for the first two columns. But as soon as I sort the third column the second one loses its sort. As far as I know for now there must be a problem with my foreach loop. Here is my code for sorting: public List<object> inhaltSortieren(List<object> zuSortierendeListe, Dictionary<string, SortierRichtung> sortierung) { IOrderedEnumerable<object> sortierteListe = null; if (sortierung.First().Value =

When to return IOrderedEnumerable?

落爺英雄遲暮 提交于 2020-01-12 06:28:07
问题 Should IOrderedEnumerable be used as a return type purely for semantic value? For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered? What about in the case that a repository wraps a stored procedure with an ORDER BY clause. Should the repository return IOrderedEnumerable ? And how would that be achieved? 回答1: I don't think it would be a good idea: Should IOrderedEnumerable be used as a return type purely

When to return IOrderedEnumerable?

久未见 提交于 2020-01-12 06:27:30
问题 Should IOrderedEnumerable be used as a return type purely for semantic value? For example, when consuming a model in the presentation layer, how can we know whether the collection requires ordering or is already ordered? What about in the case that a repository wraps a stored procedure with an ORDER BY clause. Should the repository return IOrderedEnumerable ? And how would that be achieved? 回答1: I don't think it would be a good idea: Should IOrderedEnumerable be used as a return type purely

Is it possible to turn an IEnumerable into an IOrderedEnumerable without using OrderBy?

こ雲淡風輕ζ 提交于 2019-12-28 14:02:21
问题 Say there is an extension method to order an IQueryable based on several types of Sorting (i.e. sorting by various properties) designated by a SortMethod enum. public static IOrderedEnumerable<AClass> OrderByX(this IQueryable<AClass> values, SortMethod? sortMethod) { IOrderedEnumerable<AClass> queryRes = null; switch (sortMethod) { case SortMethod.Method1: queryRes = values.OrderBy(a => a.Property1); break; case SortMethod.Method2: queryRes = values.OrderBy(a => a.Property2); break; case null

Strange behaviour of OrderBy Linq

耗尽温柔 提交于 2019-12-23 22:26:38
问题 I have a list which is ordered using the OrderBy() Linq function, that returns an IOrderedEnumerable . var testList = myList.OrderBy(obj => obj.ParamName); The ParamName is an object that can hold integer as well as string. The above orderBy orders the list based on the integer value. Now I am operating a foreach on the testList and changing the ParamName property to some string based on its integer value as follows, using (var sequenceEnum = testList.GetEnumerator()) { while (sequenceEnum

How does IOrderedEnumerable.ThenBy() in .Net work?

久未见 提交于 2019-12-21 07:28:21
问题 I want to understand how ThenBy works in .Net. (I know how to use it, I just don't understand how Microsoft implemented it!) According to the documentation, string_list.OrderBy(Function (x) x.length).ThenBy(Function (x) x) should output a list of strings ordered by length and then alphabetically. How could it possibly work?!? The first sort is by length. The second sort should undo the sorting of the first one! Assume this code: Dim sorted_by_length As IOrderedEnumerable(Of String) sorted_by

Can it be advantageous for a method to return IOrderedEnumerable<T> instead of IEnumerable<T>?

霸气de小男生 提交于 2019-12-10 14:04:48
问题 Can it be advantageous for a method to return IOrderedEnumerable instead of IEnumerable? 回答1: Only if you expect people to order that enumerable every time and would find it hard to figure out how to do this OR if you can provide a collection that implements that interface that can efficiently order its contents and is paired with an extension method that is aware of your collection. Best option is to return a specific collection type (see Richter for details on that). 99 times out of 100