A
A
Anton Fedoryan2015-12-24 14:24:30
C++ / C#
Anton Fedoryan, 2015-12-24 14:24:30

How to sort such a dictionary?

There is a class:

public class ClassKey
  {
    public int Version { get; set; }
    public DateTime Date { get; set; }
  }

And there is a completed dictionary:
Dictionary<string, ClassKey> dt = new Dictionary<string, ClassKey>();

Is there any way to group it by version and sort by date?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2015-12-24
@AnnTHony

Based on the answer of Dmitry Kovalsky , the following came out. Maybe someone will come in handy.

foreach (var tmp in dt.OrderBy(c => c.Value.Date).OrderBy(c => c.Value.Version))
      {
        listBox2.Items.Add(string.Format("{0} _ {1} _ {2}", tmp.Key, tmp.Value.Version, tmp.Value.Date));
      }

First we sort by date, then we sort the result by versions. What was needed. Grouping is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question