WebMar 7, 2013 · One simple approach is to zip with the ordering sequence: List docs = GetDocsFromDb (...).Zip (docIds, Tuple.Create) .OrderBy (x => x.Item2).Select (x => x.Item1).ToList (); Share Improve this answer Follow answered Mar 7, 2013 at 15:44 Albin Sunnanbo 46.2k 8 68 108 WebSep 17, 2010 · Using C# what is the best way to sort a List numerically? my list has items 5,7,3 and I would like them sorted 3,5,7. I know some longer ways, but I would imagine linq has a quicker way? ... [5,7,3]; values = values.OrderBy(p => p).ToList(); Share. Improve this answer. Follow edited Dec 4, 2024 at 11:56. Viktor Mellgren. 4,238 3 3 gold badges ...
A better way to do dynamic OrderBy() in C# Asontu
WebApr 2, 2024 · A better way to do dynamic OrderBy () in C#. A common feature in various applications is to sort some collection by one of it’s properties, dependent on some input like the column clicked by the user. An implementation might take a string or enum for the column plus a bool or enum for ascending vs. descending. The code then looks … http://duoduokou.com/csharp/34669811627041997908.html indian lake fishing ohio
LINQ OrderBy Method in C# With Examples - Dot Net Tutorials
WebJan 25, 2010 · Sorted by: 7. If you know the propertyname before compilation: myList = myList.OrderBy (a=>a.propertyName).ToList (); or. myList = (from m in myList order by m.propertyName).ToList (); If you don't have the property at compile time (e.g. dynamic sorting in a grid or something); try the following extension methods: static class … WebJan 22, 2013 · If you want to sort the persons list by a required dictionary element, you can do that. var people = people.Persons.OrderBy (x => x.Cars.First (kv => kv.Key == "volvo").Value). Note that this code will blow chunks if there is no key with the value "volvo" in the person's car dictionary. – Tejs Mar 17, 2011 at 1:41 Show 9 more comments 0 WebTo order a sequence by the values of the elements themselves, specify the identity function ( x => x in Visual C# or Function (x) x in Visual Basic) for keySelector. For an example of this method, see OrderByDescending (IEnumerable, Func, IComparer). indian lake golf and country club