I have a C# ArrayList with objects that includes following fields. I have around 10 objects in the ArrayList. My problem is I need to sort the ArrayList based on the StartDate available in the system which is a DateTime variable.
public int id { get; set; }
public string title {get; set;}
public bool allDay { get; set; }
public string start { get; set; }
public string end { get; set; }
public string color { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public string Location { get; set; }
public string StartDatestr { get; set; }
public string EndDatestr { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
public bool Alert { get; set; }
public bool Repeat { get; set; }
public Int32 RepeatDays { get; set; }
public Int32 CalendarID { get; set; }
public int CustomerNo { get; set; }
public string CustomerName { get; set; }
public bool IsProspect { get; set; }
public string Description { get; set; }
Can someone please enlighten me? I tried .Sort() but it just doesn’t do anything (its dump to try sort on ArrayList which has objects I know).
Thanks in advance.
Update:
List<Appointment> appointments = new List<Appointment>();
I created the List as above. Now can I sort it?
ArrayList(unless say you are on 1.1), can't you useList<yourclass>?var sortedList = appointments.OrderBy(a=>a.startDate).ToList();