Custom Linq Ordering
问题 I have over a thousand folders, each folder contains one or more files with the following names: Unordered: Alison.ext Heather.ext Molly.ext Paula.ext Sam.ext Ordered: Molly.ext Sam.ext Heather.ext Alison.ext Paula.ext I would like to write an expression to sort this list as described above. 回答1: //Creating a dictionary with the custom order var order = "MSHAP"; var orderDict = order.Select((c,i)=>new {Letter=c, Order=i}) .ToDictionary(o => o.Letter, o => o.Order); var list = new List<string>