Let's say I have a class like this
public class model
{
public int id{get;set;}
public string name{get;set;}
public string department{get;set;}
}
and I have a List of type model
List<model> modelList = List<model>();
How Can I sort the modelList by its column name with sort direction?
Ways that I tried:
public List<model> sortModelList(string columnName, SortDirection direction)
{
//Method 1:
//The below code was unable to sort by column and unable to set the sort direction
return modelList.Sort();
//Method 2:
//The below code was unable to sort by the columnName parameter and unable to set the sort direction
return modelList.OrderBy(a=>a.name)
//What I can do in order to sort the list by "columnName" parameter and set the sort direction? (Ascending / Descending)
}