我有一堂课
public class PAUserAllowedTimesModel
{
public List<AllowedTime> Times { get; set; }
public List<AllowedTime> BusyTimes { get; set; }
public DateTime SelectedDate { get; set; }
public int DateID { get; set; }
}
我有一个此类对象的列表:
List<PAUserAllowedTimesModel> model = ...
我想按 SelectedDate 对这个集合进行排序。我尝试:
public class PAUserAllowedTimesModelComparer : IComparer<ITW2012Mobile.ViewModels.PAUserAllowedTimesModel>
{
public int Compare(ViewModels.PAUserAllowedTimesModel x, ViewModels.PAUserAllowedTimesModel y)
{
if (x.SelectedDate > y.SelectedDate)
return 0;
else
return 1;
}
}
进而
model.Sort(new PAUserAllowedTimesModelComparer());
但它只是混合元素,而不是排序。怎么了?