-8

Here is my try

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


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

I try this but I got some trouble...

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

I got an error like

Cannot implicitly convert type 'System.Linq.IOrderedEnumerable'

Any clue? Thanks!!

bluish
  • 24,718
  • 26
  • 114
  • 174
NoWar
  • 34,755
  • 78
  • 302
  • 475
  • it doesnt really make sense to sort a dictionary... the values are not stored like that – Muad'Dib May 09 '12 at 19:53
  • @Muad'Dib So how do i have to sort this Dictionary? Could u help pls? – NoWar May 09 '12 at 19:55
  • dictionary does not implement IOrderdEnumerable, so you cant use OrderBy() on it. items in a dictionary are stored in an arbitrary order, there is no concept of a "first" element and a "last" element, so you cant really sort it – Muad'Dib May 09 '12 at 19:56
  • 1
    possible duplicate of [How do you sort a C# dictionary by value?](http://stackoverflow.com/questions/289/how-do-you-sort-a-c-sharp-dictionary-by-value) – Muad'Dib May 09 '12 at 19:56

1 Answers1

4

try dic.Values.OrderBy(i=>i.CreatedDateTime)

therealmitchconnors
  • 2,682
  • 1
  • 17
  • 34