Como inserir itens na lista em ordem?
Eu tenho uma lista deDateTimeOffset
objetos, e quero inserir novos na lista em ordem.
List<DateTimeOffset> TimeList = ...
// determine the order before insert or add the new item
Desculpe, preciso atualizar minha pergunta.
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
Além disso, como colocarDateTimeOffset
como o parâmetro de.OrderBy()
?
Eu também tentei:
ItemList = from s in ItemList
orderby s.PublishDate descending // .PublishDate is type DateTime
select s;
No entanto, ele retorna essa mensagem de erro,
Não é possível converter implicitamente o tipo 'System.Linq.IOrderedEnumerable' para 'System.Collections.Gerneric.List'. Existe uma conversão explícita (você está perdendo um elenco?)