c# - how to order a list by Property Value using Linq -


i need order items defined in list called preferences.

list<string> preferences = new list<string> { "first","second","third" }; ienumerable<mylist> ordereddata = mylist.orderby(item => preferences.indexof(item)); 

ordereddata output should be

first second third... //remaining property values comes here 

please give suggestion.

look index if available in preference list else use int.maxvalue keep @ end.

list<string> preferences = new list<string> { "first","second","third" }; ienumerable<mylist> ordereddata = mylist.orderby(item =>                                           {                                               var index = preferences.indexof(item);   // use property if item object.                                               return index>=0 ? index: int.maxvalue;                                          }); 

check example


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -