我有一个包含以下字段的 C# ArrayList
对象。这个 ArrayList
中大约有 10 个对象。我的问题是,我需要根据系统中的可用 StartDate
(一个 DateTime 变量)对 ArrayList
进行排序。
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; }
请问有人能给我解惑吗?我尝试使用.Sort()
,但它似乎并没有起到排序的作用(在我所知道的情况下,对于包含对象的ArrayList
进行排序是无效的)。
提前感谢您的帮助。
更新:
List<Appointment> appointments = new List<Appointment>();
我已经按照上述方式创建了
List
,现在我可以对其进行排序吗?
ArrayList
吗?难道不能使用List<yourclass>
吗? - V4Vendettavar sortedList = appointments.OrderBy(a=>a.startDate).ToList();
- L.B