W tablicy nr. Istnieje jednak bardzo przydatna klasa Dictionary
, która jest zbiorem obiektów KeyValuePair
. Jest podobny do tablicy w tym sensie, że jest to zbiór obiektów z kluczami, ale bardziej ogólny, że klucz może być dowolnego typu.
Przykład:
Dictionary<string, int> HeightInInches = new Dictionary<string, int>();
HeightInInches.Add("Joe", 72);
HeightInInches.Add("Elaine", 60);
HeightInInches.Add("Michael", 59);
foreach(KeyValuePair<string, int> person in HeightInInces)
{
Console.WriteLine(person.Key + " is " + person.Value + " inches tall.");
}
MSDN Documentation for Dictionary<TKey, TValue>
Naprawdę chce hash. – seand