I have a requirement to sort a List<List<T>>
say #myList
. T
has the properties QuestionName
and Response
.
I need to sort the #mylist
based on response to a particular question. Here's my code:
public class T
{
public string QuestionName {get; set;}
public string Response {get; set;}
}
List<List<T>> myList = new List<List<T>>();
List<T> tList = new List<T>();
tList.add({QuestionName = "FirstName", Response = "BBB"});
tList.add({QuestionName = "LastName", Response = "BBBLastName"});
myList.add(tList);
tList = new List<T>();
tList.add({QuestionName = "FirstName", Response = "AAA"});
tList.add({QuestionName = "LastName", Response = "AAACLastName"});
myList.add(tList);
tList = new List<T>();
tList.add({QuestionName = "FirstName", Response = "CCC"});
tList.add({QuestionName = "LastName", Response = "CCCLastName"});
myList.add(tList);
This basically corresponds to a table - where each T
is a cell, List<T>
is a row and List<List<T>>
is the table.
I need to sort rows of the table (List<T>
) based on the response to the FirstName question.
I searched web, but did not find a single post about sorting List<List<T>>
. Is it even possible?
>` is `myList.OrderBy(list => list.First())`
– Mrinal Kamboj Nov 07 '18 at 06:02