How do I convert from a Dictionary to a SortedDictionary using LINQ in C#?

Why use LINQ? There is a constructor for this:

new SortedDictionary<int, string>(existing);

You could add a ToSortedDictionary – but I wouldn’t bother…


Note: this is an answer to the title of the question (convert a Dictionary to a SortedDictionary for the same types, if you need additional step that OP is looking for – swap key and values in the process – as shown in the updated problem, see this answer.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)