0

I am trying to return "title" result in Ascending order. I tried with below code but ascending order was not working.

var details = DS.Tables[1].AsEnumerable()
              .GroupBy(row => row["ID"])
              .Select(row => row.FirstOrDefault()).Take(TopCount)
              .OrderBy(row => row["title"])
               .ToDictionary(row => row["ID"], row => new ObjDetails(DS.Tables[1].Columns, row));
Shakeer Hussain
  • 2,230
  • 7
  • 29
  • 52
  • 1
    `ToDictionary` destroy the order. This is a duplicate question. – Franck Apr 23 '18 at 18:43
  • 2
    A dictionary is, unfortunately, not ordered. This is one of the downsides of using an everyday word like "dictionary" to represent a set of key-value pairs; one expects that a dictionary will be sorted, like a real dictionary is. – Eric Lippert Apr 23 '18 at 18:49
  • It's not clear what exactly you're trying to do here. Can you describe what properties you would like `details` to have? One expects that a sorted dictionary will be sorted on the *keys*, but your keys are ids, not titles. This is quite confusing; say more clearly what it is that you're trying to do. – Eric Lippert Apr 23 '18 at 18:52
  • 1
    In addition to the above, it makes little sense usually to use Take() _before_ OrderBy(). – Evk Apr 23 '18 at 18:53

0 Answers0