site stats

C# order a list by another list

WebIn addition to @Daniel Brückner answer and problem defined at the end of it:. I don't like Concat() and ToList() in there. But for the moment I have no really >good way around that. I am looking for a nice trick to turn the -1 of the first >example into a big number. WebApr 7, 2016 · But the second list has only four items in it. I would like my first list to be ordered like this: A, B, C, D, X, W. Actually the last two letters X and W doesn't matter …

C# Sorting list by another list - Stack Overflow

WebMar 6, 2013 · public static IEnumerable OrderBySequence( this IEnumerable source, IEnumerable order, Func idSelector) { var … WebJan 29, 2016 · C#: Sort one collection based on another one. In order to sort a collection of objects based on another list that contains the proper order, we can create an extension method that performs a `Join` between these two collections and pass a `func` as innerKeySelector argument to allow us to sort this collection based on whatever key we … the alchemist cocktail making class https://catesconsulting.net

c# - List sort based on another list - Stack Overflow

WebList list1 = new List(); List list2 = new List(); Then I need to order the list2 based on the order of matches by a property with list1 . Example: WebAug 12, 2010 · Question is though, how could I go about ordering an 'options_list' by utilising the 'Type_ID' on the object which would relate to the ordering of the types_list. As in something like (obviously this isn't valid - but hopefully you will get the idea!) options_list.OrderBy(x => x.Type_ID == types_list.OrderBy(e => e.Ordering)); WebNov 16, 2016 · You can use Linq to order your users: using System.Linq; mylist.OrderBy (x => x.LastName); If you have same last names you can order users by middle name. If you have same middle names you can order users by first name: mylist.OrderBy (x => x.LastName).ThenBy (x => x.MiddleName).ThenBy (x => x.FirstName); Share Improve … the alchemist cocktail bar manchester

C# sort list in alphabetical order - Stack Overflow

Category:C#: Sort one collection based on another one - Paris Polyzos

Tags:C# order a list by another list

C# order a list by another list

c# - Sort one list by another - Stack Overflow

WebDec 19, 2024 · \$\begingroup\$ Further to the comment about automagic projection: I would be inclined to separate that functionality out into it's own 'module' (if not using a pre-built one), so that you can retrieve a translator between T1 and T2 (e.g. Func Mapping.Mapper()).My experience with reflection has always been that … WebNov 11, 2012 · names.Select ( (n, index) => new { Name = n, Index = index }) .OrderBy (x => numbers.ElementAtOrDefault (x.Index)) .Select (x => x.Name) .ToList (); But i would use another collection type like Dictionary instead if both lists are related …

C# order a list by another list

Did you know?

WebApr 2, 2013 · c# - Find items from a list which exist in another list - Stack Overflow Find items from a list which exist in another list Ask Question Asked 10 years ago Modified 2 years, 7 months ago Viewed 93k times 53 I have a List PropA { int a; int b; } and another List PropX { int a; int b; } WebMay 1, 2024 · Another approach is to use overload of the method Array.Sort with IComparer. At first we should implement IComparer: private class PeopleComparer : IComparer { public int Compare (Person x, Person y) { return x.Name.CompareTo (y.Name); } } And then we can sort two our arrays:

WebDec 26, 2012 · Since a List is a reference type, what is passed to the function is a reference to the original list. See this MSDN article for more information about how parameters are passed in C#. In order to achieve what you want, you should create a copy of the list in SomeOperationFunction and return this instead. A simple example: WebMay 28, 2013 · C# Check if a List is a part of another List [duplicate] Ask Question Asked 9 years, 10 months ago. Modified 4 years, 6 months ago. Viewed 25k ... Given two IEnumerables it will return a list of any values that exist in both. var presentInBoth = query1.Intersect(query2) You may well need to call .ToList() query1 and query2 to make …

WebOct 17, 2013 · The first list will define the order for the matched objects - the actual order doesn't matter, so long as both lists are ordered the same. Example below [pseudocode] shows what I mean, where the second list is sorted by TargetId to … WebMar 7, 2016 · 1 Answer. You can do select the index of the item, throw it into an anonymous object order by that and then select the string again : var res = kws .Select (a=>new {orderOf=order.IndexOf (a.fkp_keyword),val=a}) .OrderBy (a=>a.orderOf) .Select (a=>a.val) .ToList (); If you have items that are not in the list you are ordering by then they will be ...

WebMar 18, 2024 · IList Items = new List (); Items.Add ( new Item () {Id = 10, Name = 'X'}); Items.Add ( new Item () {Id = 11, Name = 'Y'}); Items.Add ( new Item () {Id = 12, Name = 'Z'}); Items.Add ( new Item () {Id = 13, Name = 'A'}); //Comparing list // The below list contains Ids but not in a different order compared to the above list

WebJul 22, 2010 · Simplest way to order a list is to use OrderBy List objListOrder = source.OrderBy (order => order.OrderDate).ToList (); If you want to order by multiple columns like following SQL Query. ORDER BY OrderDate, OrderId To achieve this you can use ThenBy like following. the future navigators guideWebApr 30, 2010 · Daniel is nearly right, but an easy way to use the order of the incoming list is to order by the index of the ID in that list: public List GetMyTypes (List ids) { return (from myType in db.MyTypes where ids.Contains (myType.Id) orderby ids.IndexOf (myType.Id) select myType).ToList (); } the future nathanielWebFeb 26, 2015 · You can use List.IndexOf and use int.Maxvalue if it returns -1: List result = list.OrderBy (str => { int index = comparer.IndexOf (str); return index == -1 ? int.MaxValue : index; }).ToList (); Here is a … the alchemist cocktail classWebDec 13, 2024 · If you want to order by nested elements, you could do it like this: query = query.OrderByDescending (x => { x.CourseProgresses = x.CourseProgresses.OrderByDescending (y => y.UpdateDate)); return x.Id; } Share Improve this answer Follow answered Dec 13, 2024 at 10:20 Sebastian Siemens 2,292 1 17 23 the alchemist code kanon j+the alchemist - cocktail barWebJan 2, 2024 · Here I'm merging a list to end of another list after sorting it according to another list.This should sort processdetails list according to the order in routeplans list if any item not present in processdetails list is found it should keep the order and add it to processdetails list. the alchemist cocktail makingWebFeb 23, 2024 · We now have the order of the letters that we want listB to reflect: First, the order given by listA, then, the remaning letters present in listB. The .Join() operation .Join() associates an outer sequence with an inner sequence based on association keys defined by a key selector for each sequence ; and then returns an IEnumerable from the ... the future network of intelligence institute