C# linq orderby 2 fields
Is this a neat trick with doubling the most significant value's comparer or is there a better way? Which is a female dog because I can't connect a mouse nor keyboard. Hot Network Questions. Now it's on-topic again. Also, be prepared to get bashed pretty hard for having a class named Thing Home Questions Tags Users Unanswered. This looks like pseudo-code and is not fit for reviewing!
y(x => ate).ThenByDescending(x => e). LINQ - OrderBy, OrderByDescending, ThenBy, ThenByDescending, GroupBy, ToLookUp | Test your C# code online Fiddle LINQ query syntax supports multiple sorting fields seperated by comma whereas you have to use ThenBy. A simple one, but I did spend some time on how to do it with Lambda Expression in C#.
Ordering data in LINQ Queries by more than one column Daily .NET Tips
C# provides the OrderBy, OrderByDescending, ThenBy.
ToList. A pretty common scenario, even in our tiny example - just imagine that Jane and John are the same age and their kids are twins.
In this case, dcastro has been kind enough to update his answer, but this should not be expected. Home Questions Tags Users Unanswered. It looks like your implementation relies on Width.
i found some info but few area is not clear.
c Sorting array with respect to two properties Code Review Stack Exchange
one use is. Columnname) in a LINQ query, we can easily order data in a source collection.
This means that we can OrderBy on multiple fields by chaining OrderBy() Web development in with C# and MS sql server are the.
But instead of fixing your implementation, I would suggest using LINQ's OrderBy and ThenBy instead.
Multiple column name in order by with LINQ
It doesn't seem like you need to sort the.
You can even chain multiple ThenBy method calls, in case your data is more complex than the data from our test case. As you can see, the syntax is slightly different - the direction ascending or descending is specified directly after the field to order by ascending is actually implicit, but I included it to show you the difference.
They do just what the name indicates: Control the order after the initial sort. This article has been fully translated into the following languages: Chinese German Portuguese. Hot Network Questions.
Video: C# linq orderby 2 fields C# LINQ - Grouping By Multiple Fields