我有一个DateTimeOffset
对象列表,我想按顺序将新的对象插入到列表中。
List<DateTimeOffset> TimeList = ...
// determine the order before insert or add the new item
抱歉,我需要更新我的问题。
List<customizedClass> ItemList = ...
//customizedClass contains DateTimeOffset object and other strings, int, etc.
ItemList.Sort(); // this won't work until set data comparison with DateTimeOffset
ItemList.OrderBy(); // this won't work until set data comparison with DateTimeOffset
此外,如何将
DateTimeOffset
作为.OrderBy()
的参数?我还尝试过:
ItemList = from s in ItemList
orderby s.PublishDate descending // .PublishDate is type DateTime
select s;
然而,它返回了以下错误信息:
“无法隐式转换类型'System.Linq.IOrderedEnumerable'为'System.Collections.Gerneric.List'。存在显式转换(是否缺少强制转换?)”
List<T>
是一个有序的集合。您想要进行排序吗? - KV PrajapatiSortedBag<T>
:在 .NET 中是否有排序集合类型? - nawfal