如何按值的日期时间属性对字典进行排序

本文关键字:字典 排序 属性 何按值 日期 时间 | 更新日期: 2023-09-27 18:33:36

这是我的尝试

public MyClass
{
   public Guid ID {set; get;}
   public DateTime CreatedDateTime {set; get;}
}

ConcurrentDictionary<Guid, MyClass> dic = new ConcurrentDictionary<Guid,MyClass>();

我试过这个,但我遇到了一些麻烦...

dic.OrderBy(i=>i.Value.CreatedDateTime);

我收到一个错误,例如

Cannot implicitly convert type 'System.Linq.IOrderedEnumerable'

有什么线索吗?谢谢!!

如何按值的日期时间属性对字典进行排序

尝试dic.Values.OrderBy(i=>i.CreatedDateTime)