2012-05-09 52 views
-7

这里是我的尝试如何通过价值datetime属性进行排序字典

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' 

任何线索?谢谢!!

+0

它并不真正意义的排序字典...的值不存储这样的 –

+0

@ Muad'Dib所以我一定如何将这个字典排序?你能帮忙吗? –

+0

字典没有实现IOrderdEnumerable,所以你不能使用OrderBy()。在一本字典中的项目是以任意顺序存储的,没有“第一个”元素和“最后一个”元素的概念,所以你真的不能排序它 –

回答

相关问题