I have a List of DateTimeOffset
objects, and I want to insert new ones into the list in order.
List<DateTimeOffset> TimeList = ...
// determine the order before insert or add the new item
Sorry, need to update my question.
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
Also, how to put DateTimeOffset
as the parameter of .OrderBy()
?
I have also tried:
ItemList = from s in ItemList
orderby s.PublishDate descending // .PublishDate is type DateTime
select s;
However, it returns this error message,
Cannot implicitly convert type 'System.Linq.IOrderedEnumerable' to 'System.Collections.Gerneric.List'. An explicit conversion exist (are you missing a cast?)
List<T>
is ordered` collection. Do you wish to *sort? – RhotacismSortedBag<T>
: is-there-a-sorted-collection-type-in-net – Conservator