using System.Collections.Generic;
public string DEP {get;set;}
public string ARR {get;set;}
public string KEY {get;set;}
public static void Main()
List<Station> lstTemp1 = new List<Station>();
lstTemp1.Add(new Station() { ARR = "CDG", DEP = "TPE" , KEY = "c" });
lstTemp1.Add(new Station() { ARR = "ADG", DEP = "CAN" , KEY = "b" });
lstTemp1.Add(new Station() { ARR = "CDG", DEP = "AXX" , KEY = "a" });
lstTemp1.Add(new Station() { ARR = "BHR", DEP = "BKK" , KEY = "a" });
lstTemp1.Add(new Station() { ARR = "LHR", DEP = "AXX" , KEY = "a" });
lstTemp1.Add(new Station() { ARR = "BHR", DEP = "AXX" , KEY = "a" });
foreach (var str in lstTemp1)
Console.WriteLine(str.ARR + "," +str.DEP + "," +str.KEY + "," );
Console.WriteLine("----------------------------------------");
List<Station> lstTemp2 = lstTemp1.OrderBy(s => s.KEY).ThenBy(s => s.DEP).ThenBy(s => s.ARR).ToList();
foreach (var str in lstTemp2)
Console.WriteLine(str.ARR + "," +str.DEP + "," +str.KEY + "," );
Console.WriteLine("----------------------------------------");
List<Station> lstTemp3 = (from a in lstTemp1
orderby a.KEY ascending, a.DEP ascending, a.ARR ascending
foreach (var str in lstTemp3)
Console.WriteLine(str.ARR + "," +str.DEP + "," +str.KEY + "," );
Console.WriteLine("----------------------------------------");
Dictionary<string, int> list = new Dictionary<string, int>();
Dictionary<string, int> lstOrderKey = orderKey.Split(',').Select((s, index) => new { s, index }).ToDictionary(o => o.s , o => o.index);
var lstTemp4 = (from a in lstTemp1
join b in lstOrderKey on a.KEY equals b.Key
).Union(from a in lstTemp1
join b in lstOrderKey on a.KEY equals b.Key into g
from b in g.DefaultIfEmpty()
foreach (var str in lstTemp4)
Console.WriteLine(str.ARR + "," +str.DEP + "," +str.KEY + "," );