I have a record class like this :
public class RecordInfo
{
public String CDate;
public String Patient_ID;
public Color Zone;
public String Fname;
public String Lname;
public Int64 ImgSize;
public String ImagePrefix;
public String ImagePath;
public String Sex;
public String TZ;
}
and I made a list of RecordInfo like this :
List<RecordInfo> PatientRecords = new List<RecordInfo>();
and I added records to it, but I would like to sort that list based on Patient_ID, sex, Fname, etc…..
Any idea how can I do that?
Sure, LINQ makes it easy using
OrderBy,OrderByDescending,ThenByandThenByDescending:That will create a new list – LINQ is based on queries which project one sequence onto a new one, rather than mutating the existing list.
Alternatively, you could use
List<T>.Sortwith a custom comparer to sort in-place.Either way, I’d strongly recommend using properties instead of public fields, and also following .NET naming conventions.