{ { 0, "Test0" }, {...">

"Dictionary Types" in .Net

I used common dictionaries in C #. Such things as:

var example = new Dictionary<int, string> { 
                                        { 0, "Test0" }, 
                                        { 1, "Test1" } };

I vaguely remember that I was told that before generics you can use Hashtable (). Basically the same thing, but without a specific type (so that type values ​​will be put in a box, I think).

var example2 = new Hashtable {
                          {0, "Test0"},
                          {1, "Test1"} };

And there are questions like this question, why do we prefer the dictionary by Hashtables ( Why is the dictionary preferable to a hash table? ).

But what about all the other types of vocabulary ?

SortedList<K,V>. List, , / ( , ?). IDictionary<TKey,TValue>. , SortedDictionary ( SortedList SortedDictionary?)

- , ?

, .Net 4.5 ... , , , Hashtable ?

+4
2

Dictionary Hashtable - . , .

A List , . "" , , , .

A Dictionary . . Dictionary .

- - , , , .

, ArrayList List<T>, , Hashtable Dictionary<T, U> - , .

+3

Dictionary<TKey,TValue>. - .


, OrderedDictionary.

, .

OrderedDictioanry childToIcecream = new OrderedDictionary();
childToIcecream["Jake"] = "Vanilla";
childToIcecream["Kevin"] = "Chocolate";
childToIcecream["Megan"] = "Strawberry";

. ( = 0, = 1..) , , . , , , . List<string> . / .

, , - ,


. , / , , , , .

SortedDictionary<char, string> letterToWord = new SortedDictionary<char, string>();
letterToWord['b'] = "bat";    
letterToWord['c'] = "cat";    
letterToWord['a'] = "apple";

, , , , . , .


TL;DR; Dictionary<TKey, TValue>, , .

+3

Source: https://habr.com/ru/post/1541895/


All Articles