WebMay 5, 2011 · I have a list of MyFirstObject called AList. MyFirstObject class has two properties: ID, Name. I have another list of MySecondObject called BList. MySecondObject only has a property:ID. AList is ordered by its ID property. BList is randomly ordered and not by its ID property. We want to achieve the order of BList in AList. (Apologies for the ... WebApr 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 (); }
c# - Order List in same order as another list - Stack Overflow
WebMay 24, 2012 · 1. Try using some linq. List itm = new List; //Fill itm with data //get selected item from control string selectedcategory = cboCatetories.SelectedItem; var itms = from BO in itm where itm.ItemCategory = selectedcategory select itm; itms now contains all items in that category. Share. WebNov 20, 2024 · Using extension methods, first OrderBy the enum, ThenBy name. var sorted = list.OrderBy ( m => m.Sort ).ThenBy ( m => m.Name ); Share Improve this answer Follow answered Mar 10, 2010 at 2:59 tvanfosson 521k 98 699 794 Add a comment 5 Aside from the nice LINQ solutions, you can also do this with a compare method like you mentioned. swirly test
ChatGPT cheat sheet: Complete guide for 2024
WebJan 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. WebApr 7, 2016 · 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 how they are ordered, but they should be at the … 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 ... swirly straw glasses