. , KeyValuePairCTKey, TValue> , DictionaryCTKey, TValue> . DictionaryCTKey, TValue>, , foreach KeyValuePair.
DictionaryCTKey, TValue> , , . . DictionaryCTKey, TValue> .
DictionaryCTKey, TValueX
// // DictionaryCTKey, TValueX
Using System;
Using System.Collections.Generic;
class GenDictionaryDemo { static void Main() {
// // .
Dictionarycstring, double> diet =
new Dictionarycstring, double>();
// , diet.Add(", ", 73000); diet.Add(", Capa", 59000); diet.Add(", ", 45000); diet.Add(", ", 99000);
// , .. .
ICollection<string> = diet.Keys;
// , .. , foreach(string str in )
Console.WriteLine ("{0}, : {1:C}", str, diet[str]);
}
}
.
, , : $73,000.00 , , : $59,000.00 , , : $45,000.00 , , : $99,000.00
SortedDictionary<TKey, TValue>
SortedDictionary<TKey, TValue> "-" , DictionaryCTKey, TValue>, , . SortedDictionary<TKey, TValue> IDictionary, IDictionary<TKey, TValue>, ICollection, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable IEnumerable<KeyValuePair<TKey, TValue>>. SortedDictionary<TKey, TValue> .
Public SortedDictionary()
public SortedDictionary(IDictionary<TKey, TValue> dictionary)
public SortedDictionary(IComparer<TKey> comparer)
public SortedDictionary(IDictionaryCTKey, TValue> dictionary,
IComparer<TKey> comparer)
, dictionary. comparer IComparer , , , .
|
|
SortedDictionary<TKey, TValue> . . 25.18.
25.18. , SortedDictionaryCTKey, TValue>
public void Add (TKey key, -", TValue value) key value.
key , , ArgumentException public bool ContainsKey (TKey true, - ) key -
_; false
Public bool
ContainsValue(TValue value) public bool Remove(TKey key)
true, value; false key . true, key false
, SortedDictionary<TKey, TValue> , , , . .
public Icomparer<TKey> Comparer { get; ]
public SortedDictionaryCTKey, TValue>. KeyCollection Keys { get; } public SortedDictionary<TKey, TValue>. ValueCollection Values { get; }
\
, , , Keys Values. SortedDictionary<TKey, TValue>.KeyCollection SortedDictionary<TKey, TValu*e>. ValueCollection , ICollection IEnumerable.
, SortedDictionary<TKey, TValue> , IDictionary<TKey, TValueX
public TValue this[TKey key] { get; set; }
, . , .
SortedDictionary<TKey, TValue> "-" KeyValuePair<TKey, TValueX , .