In what order are couples stored in Dictionary<string, string=""> C#?</string,>
-
There's a challenge: to organise a pair of keys. A collection was selected for steam storage.
Dictionary<string, string>
♪- How are the elements of this collection stored as they are added?
- Can they be treated on an index like in a mass or a sheet?
- Is there any sort of order in this collection, and does it change from the decoration of adding elements?
-
Dictonary implemented as https://msdn.microsoft.com/ru-ru/library/xfhwa508%28v=vs.110%29.aspx so no one guarantees you the order of the elements or the fact that it will remain unchanged when appended, removed. You can't turn on the index either.
But Dictonary can use Linq, then:
Dictonary<string, string> dict = new Dictonary<string, string>() { {"red", "dog"} , {"yellow", "cat"} , {"green", "hamster"} }; var sorted = dict.OrderBy(n => n.Key);
Let me get you some sorting.
NB! sorted isn't a dictionary anymore, it's IEnumerable.