有人可以教我如何在C#中按顺序插入项目到列表中?
我有一个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;
但是,它返回此错误消息,
Cannot implicitly convert type ‘System.Linq.IOrderedEnumerable’ to ‘System.Collections.Gerneric.List’. An explicit conversion exist (are you missing a cast?)
解决方法
原文地址:https://www.jb51.cc/csharp/94424.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。