I have a list of type Test
List<Test> testList = new List<Test>
{ new Test { TestName="gold", CriteriaOne = "sport", CriteriaTwo = "Outdoors" },
{ new Test { TestName="silver", CriteriaOne = "sport", CriteriaTwo = "Indoors" },
{ new Test { TestName="bronze", CriteriaOne = "activity", CriteriaTwo = "Water" },
{ new Test { TestName="gold", CriteriaOne = "activity", CriteriaTwo = "Outdoors" },
//some more tests ... };
I have a list for each criteria
// List of strings to order testListBy first.
List<String> criteriaOneOrder = new List<String> { "sport", "activity", "warmup", "other"};
//List of strings to order testListBy second.
List<String> criteriaTwoOrder = new List<String> { "OutDoors", "Indoors", "Water", "Other"};
I want to order by list of type test firstly based on the criteriaOneOrder list then if two results are the same, ie. more than one sport then order them on the second string so that a outdoor sport will be listed before indoor sport.
I've tried using Lambda expressions making use of the OrderyBy function and the IndexOf to try and reorder the list but have not been successful so far.
testList = testList.OrderBy(t => criteriaOneOrder.IndexOf(t.CriteriaOne)).ToList()
Any ideas?