13 [DebuggerTypeProxy(typeof(Mscorlib_DictionaryDebugView<, >))]
14 [DebuggerDisplay(
"Count = {Count}")]
16 [__DynamicallyInvokable]
17 public class Dictionary<TKey, TValue> :
IDictionary<TKey, TValue>,
ICollection<KeyValuePair<TKey, TValue>>,
IEnumerable<KeyValuePair<TKey, TValue>>,
IEnumerable,
IDictionary,
ICollection,
IReadOnlyDictionary<TKey, TValue>,
IReadOnlyCollection<KeyValuePair<TKey, TValue>>,
ISerializable,
IDeserializationCallback 32 [__DynamicallyInvokable]
43 private int getEnumeratorRetType;
45 internal const int DictEntry = 1;
51 [__DynamicallyInvokable]
54 [__DynamicallyInvokable]
64 [__DynamicallyInvokable]
67 [__DynamicallyInvokable]
70 if (index == 0 || index == dictionary.count + 1)
72 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
74 if (getEnumeratorRetType == 1)
85 [__DynamicallyInvokable]
88 [__DynamicallyInvokable]
91 if (index == 0 || index == dictionary.count + 1)
93 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
102 [__DynamicallyInvokable]
105 [__DynamicallyInvokable]
108 if (index == 0 || index == dictionary.count + 1)
110 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
119 [__DynamicallyInvokable]
122 [__DynamicallyInvokable]
125 if (index == 0 || index == dictionary.count + 1)
127 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
129 return current.
Value;
135 this.dictionary = dictionary;
136 version = dictionary.version;
138 this.getEnumeratorRetType = getEnumeratorRetType;
146 [__DynamicallyInvokable]
149 if (version != dictionary.version)
151 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
153 while ((uint)index < (uint)dictionary.count)
155 if (dictionary.entries[index].hashCode >= 0)
163 index = dictionary.count + 1;
169 [__DynamicallyInvokable]
176 [__DynamicallyInvokable]
179 if (version != dictionary.version)
181 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
190 [DebuggerTypeProxy(typeof(Mscorlib_DictionaryKeyCollectionDebugView<, >))]
191 [DebuggerDisplay(
"Count = {Count}")]
192 [__DynamicallyInvokable]
197 [__DynamicallyInvokable]
206 private TKey currentKey;
210 [__DynamicallyInvokable]
213 [__DynamicallyInvokable]
223 [__DynamicallyInvokable]
226 [__DynamicallyInvokable]
229 if (index == 0 || index == dictionary.count + 1)
231 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
239 this.dictionary = dictionary;
240 version = dictionary.version;
242 currentKey =
default(TKey);
246 [__DynamicallyInvokable]
255 [__DynamicallyInvokable]
258 if (version != dictionary.version)
260 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
262 while ((uint)index < (uint)dictionary.count)
264 if (dictionary.entries[index].hashCode >= 0)
266 currentKey = dictionary.entries[index].key;
272 index = dictionary.count + 1;
273 currentKey =
default(TKey);
279 [__DynamicallyInvokable]
282 if (version != dictionary.version)
284 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
287 currentKey =
default(TKey);
295 [__DynamicallyInvokable]
298 [__DynamicallyInvokable]
301 return dictionary.Count;
308 [__DynamicallyInvokable]
311 [__DynamicallyInvokable]
321 [__DynamicallyInvokable]
324 [__DynamicallyInvokable]
333 [__DynamicallyInvokable]
334 object ICollection.SyncRoot
336 [__DynamicallyInvokable]
339 return ((ICollection)dictionary).SyncRoot;
347 [__DynamicallyInvokable]
350 if (dictionary ==
null)
352 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
354 this.dictionary = dictionary;
359 [__DynamicallyInvokable]
373 [__DynamicallyInvokable]
374 public void CopyTo(TKey[] array,
int index)
378 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
380 if (index < 0 || index > array.Length)
382 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
384 if (array.Length - index < dictionary.Count)
386 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
388 int count = dictionary.count;
389 Entry[] entries = dictionary.entries;
390 for (
int i = 0; i < count; i++)
392 if (entries[i].hashCode >= 0)
394 array[index++] = entries[i].key;
402 [__DynamicallyInvokable]
405 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
410 [__DynamicallyInvokable]
413 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
420 [__DynamicallyInvokable]
423 return dictionary.ContainsKey(item);
431 [__DynamicallyInvokable]
432 bool ICollection<TKey>.Remove(TKey item)
434 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
440 [__DynamicallyInvokable]
441 IEnumerator<TKey> IEnumerable<TKey>.GetEnumerator()
443 return new Enumerator(dictionary);
448 [__DynamicallyInvokable]
449 IEnumerator IEnumerable.GetEnumerator()
451 return new Enumerator(dictionary);
464 [__DynamicallyInvokable]
465 void ICollection.CopyTo(Array array,
int index)
469 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
473 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
475 if (array.GetLowerBound(0) != 0)
477 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
479 if (index < 0 || index > array.Length)
481 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
483 if (array.Length - index < dictionary.Count)
485 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
487 TKey[] array2 = array as TKey[];
493 object[] array3 = array as
object[];
496 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
498 int count = dictionary.count;
499 Entry[] entries = dictionary.entries;
502 for (
int i = 0; i < count; i++)
504 if (entries[i].hashCode >= 0)
506 array3[index++] = entries[i].key;
510 catch (ArrayTypeMismatchException)
512 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
519 [DebuggerTypeProxy(typeof(Mscorlib_DictionaryValueCollectionDebugView<, >))]
520 [DebuggerDisplay(
"Count = {Count}")]
521 [__DynamicallyInvokable]
526 [__DynamicallyInvokable]
535 private TValue currentValue;
539 [__DynamicallyInvokable]
542 [__DynamicallyInvokable]
552 [__DynamicallyInvokable]
555 [__DynamicallyInvokable]
558 if (index == 0 || index == dictionary.count + 1)
560 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
568 this.dictionary = dictionary;
569 version = dictionary.version;
571 currentValue =
default(TValue);
575 [__DynamicallyInvokable]
584 [__DynamicallyInvokable]
587 if (version != dictionary.version)
589 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
591 while ((uint)index < (uint)dictionary.count)
593 if (dictionary.entries[index].hashCode >= 0)
595 currentValue = dictionary.entries[index].value;
601 index = dictionary.count + 1;
602 currentValue =
default(TValue);
608 [__DynamicallyInvokable]
611 if (version != dictionary.version)
613 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
616 currentValue =
default(TValue);
624 [__DynamicallyInvokable]
627 [__DynamicallyInvokable]
630 return dictionary.Count;
637 [__DynamicallyInvokable]
640 [__DynamicallyInvokable]
650 [__DynamicallyInvokable]
653 [__DynamicallyInvokable]
662 [__DynamicallyInvokable]
663 object ICollection.SyncRoot
665 [__DynamicallyInvokable]
668 return ((ICollection)dictionary).SyncRoot;
676 [__DynamicallyInvokable]
679 if (dictionary ==
null)
681 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
683 this.dictionary = dictionary;
688 [__DynamicallyInvokable]
702 [__DynamicallyInvokable]
703 public void CopyTo(TValue[] array,
int index)
707 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
709 if (index < 0 || index > array.Length)
711 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
713 if (array.Length - index < dictionary.Count)
715 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
717 int count = dictionary.count;
718 Entry[] entries = dictionary.entries;
719 for (
int i = 0; i < count; i++)
721 if (entries[i].hashCode >= 0)
723 array[index++] = entries[i].value;
731 [__DynamicallyInvokable]
734 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
742 [__DynamicallyInvokable]
745 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
751 [__DynamicallyInvokable]
754 ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
761 [__DynamicallyInvokable]
762 bool ICollection<TValue>.Contains(TValue item)
764 return dictionary.ContainsValue(item);
769 [__DynamicallyInvokable]
770 IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator()
772 return new Enumerator(dictionary);
777 [__DynamicallyInvokable]
778 IEnumerator IEnumerable.GetEnumerator()
780 return new Enumerator(dictionary);
793 [__DynamicallyInvokable]
794 void ICollection.CopyTo(Array array,
int index)
798 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
802 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
804 if (array.GetLowerBound(0) != 0)
806 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
808 if (index < 0 || index > array.Length)
810 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
812 if (array.Length - index < dictionary.Count)
814 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
816 TValue[] array2 = array as TValue[];
822 object[] array3 = array as
object[];
825 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
827 int count = dictionary.count;
828 Entry[] entries = dictionary.entries;
831 for (
int i = 0; i < count; i++)
833 if (entries[i].hashCode >= 0)
835 array3[index++] = entries[i].value;
839 catch (ArrayTypeMismatchException)
841 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
846 private int[] buckets;
848 private Entry[] entries;
854 private int freeList;
856 private int freeCount;
858 private IEqualityComparer<TKey> comparer;
860 private KeyCollection keys;
862 private ValueCollection values;
864 private object _syncRoot;
866 private const string VersionName =
"Version";
868 private const string HashSizeName =
"HashSize";
870 private const string KeyValuePairsName =
"KeyValuePairs";
872 private const string ComparerName =
"Comparer";
876 [__DynamicallyInvokable]
877 public IEqualityComparer<TKey>
Comparer 879 [__DynamicallyInvokable]
888 [__DynamicallyInvokable]
891 [__DynamicallyInvokable]
894 return count - freeCount;
900 [__DynamicallyInvokable]
901 public KeyCollection
Keys 903 [__DynamicallyInvokable]
908 keys =
new KeyCollection(
this);
914 [__DynamicallyInvokable]
917 [__DynamicallyInvokable]
922 keys =
new KeyCollection(
this);
928 [__DynamicallyInvokable]
929 IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys
931 [__DynamicallyInvokable]
936 keys =
new KeyCollection(
this);
944 [__DynamicallyInvokable]
945 public ValueCollection
Values 947 [__DynamicallyInvokable]
952 values =
new ValueCollection(
this);
958 [__DynamicallyInvokable]
961 [__DynamicallyInvokable]
966 values =
new ValueCollection(
this);
972 [__DynamicallyInvokable]
973 IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values
975 [__DynamicallyInvokable]
980 values =
new ValueCollection(
this);
992 [__DynamicallyInvokable]
993 public TValue
this[TKey key]
995 [__DynamicallyInvokable]
998 int num = FindEntry(key);
1001 return entries[num].value;
1003 ThrowHelper.ThrowKeyNotFoundException();
1004 return default(TValue);
1006 [__DynamicallyInvokable]
1009 Insert(key, value, add:
false);
1013 [__DynamicallyInvokable]
1016 [__DynamicallyInvokable]
1026 [__DynamicallyInvokable]
1027 bool ICollection.IsSynchronized
1029 [__DynamicallyInvokable]
1038 [__DynamicallyInvokable]
1039 object ICollection.SyncRoot
1041 [__DynamicallyInvokable]
1044 if (_syncRoot ==
null)
1055 [__DynamicallyInvokable]
1056 bool IDictionary.IsFixedSize
1058 [__DynamicallyInvokable]
1068 [__DynamicallyInvokable]
1069 bool IDictionary.IsReadOnly
1071 [__DynamicallyInvokable]
1080 [__DynamicallyInvokable]
1081 ICollection IDictionary.Keys
1083 [__DynamicallyInvokable]
1092 [__DynamicallyInvokable]
1093 ICollection IDictionary.Values
1095 [__DynamicallyInvokable]
1109 [__DynamicallyInvokable]
1110 object IDictionary.this[
object key]
1112 [__DynamicallyInvokable]
1115 if (IsCompatibleKey(key))
1117 int num = FindEntry((TKey)key);
1120 return entries[num].value;
1125 [__DynamicallyInvokable]
1130 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1132 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<TValue>(value, ExceptionArgument.value);
1135 TKey key2 = (TKey)key;
1138 this[key2] = (TValue)value;
1140 catch (InvalidCastException)
1142 ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
1145 catch (InvalidCastException)
1147 ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
1153 [__DynamicallyInvokable]
1163 [__DynamicallyInvokable]
1171 [__DynamicallyInvokable]
1182 [__DynamicallyInvokable]
1187 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
1191 Initialize(capacity);
1202 [__DynamicallyInvokable]
1215 [__DynamicallyInvokable]
1217 : this((dictionary != null) ? dictionary.
Count : 0, comparer)
1219 if (dictionary ==
null)
1221 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
1225 Add(item.Key, item.Value);
1234 HashHelpers.SerializationInfoTable.Add(
this, info);
1243 [__DynamicallyInvokable]
1244 public void Add(TKey key, TValue value)
1246 Insert(key, value, add:
true);
1249 [__DynamicallyInvokable]
1255 [__DynamicallyInvokable]
1258 int num = FindEntry(keyValuePair.Key);
1259 if (num >= 0 && EqualityComparer<TValue>.
Default.Equals(entries[num].value, keyValuePair.Value))
1266 [__DynamicallyInvokable]
1267 bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> keyValuePair)
1269 int num = FindEntry(keyValuePair.Key);
1270 if (num >= 0 && EqualityComparer<TValue>.Default.Equals(entries[num].value, keyValuePair.Value))
1272 Remove(keyValuePair.Key);
1279 [__DynamicallyInvokable]
1284 for (
int i = 0; i < buckets.Length; i++)
1302 [__DynamicallyInvokable]
1305 return FindEntry(key) >= 0;
1312 [__DynamicallyInvokable]
1317 for (
int i = 0; i < count; i++)
1319 if (entries[i].hashCode >= 0 && entries[i].value ==
null)
1328 for (
int j = 0; j < count; j++)
1330 if (entries[j].hashCode >= 0 && @
default.Equals(entries[j].value, value))
1343 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
1345 if (index < 0 || index > array.Length)
1347 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
1349 if (array.Length - index <
Count)
1351 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
1354 Entry[] array2 = entries;
1355 for (
int i = 0; i < num; i++)
1357 if (array2[i].hashCode >= 0)
1359 array[index++] =
new KeyValuePair<TKey, TValue>(array2[i].key, array2[i].value);
1366 [__DynamicallyInvokable]
1369 return new Enumerator(
this, 2);
1372 [__DynamicallyInvokable]
1375 return new Enumerator(
this, 2);
1388 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info);
1390 info.AddValue(
"Version", version);
1391 info.AddValue(
"Comparer", HashHelpers.GetEqualityComparerForSerialization(comparer), typeof(
IEqualityComparer<TKey>));
1392 info.AddValue(
"HashSize", (buckets !=
null) ? buckets.Length : 0);
1393 if (buckets !=
null)
1401 private int FindEntry(TKey key)
1405 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1407 if (buckets !=
null)
1409 int num = comparer.GetHashCode(key) &
int.MaxValue;
1410 for (
int num2 = buckets[num % buckets.Length]; num2 >= 0; num2 = entries[num2].next)
1412 if (entries[num2].hashCode == num && comparer.Equals(entries[num2].key, key))
1421 private void Initialize(
int capacity)
1423 int prime = HashHelpers.GetPrime(capacity);
1424 buckets =
new int[prime];
1425 for (
int i = 0; i < buckets.Length; i++)
1429 entries =
new Entry[prime];
1433 private void Insert(TKey key, TValue value,
bool add)
1437 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1439 if (buckets ==
null)
1443 int num = comparer.GetHashCode(key) &
int.MaxValue;
1444 int num2 = num % buckets.Length;
1446 for (
int num4 = buckets[num2]; num4 >= 0; num4 = entries[num4].next)
1448 if (entries[num4].hashCode == num && comparer.Equals(entries[num4].key, key))
1452 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate);
1454 entries[num4].value = value;
1464 freeList = entries[num5].next;
1469 if (count == entries.Length)
1472 num2 = num % buckets.Length;
1477 entries[num5].hashCode = num;
1478 entries[num5].next = buckets[num2];
1479 entries[num5].key = key;
1480 entries[num5].value = value;
1481 buckets[num2] = num5;
1483 if (num3 > 100 && HashHelpers.IsWellKnownEqualityComparer(comparer))
1485 comparer = (IEqualityComparer<TKey>)HashHelpers.GetRandomizedEqualityComparer(comparer);
1486 Resize(entries.Length, forceNewHashCodes:
true);
1495 HashHelpers.SerializationInfoTable.TryGetValue(
this, out
SerializationInfo value);
1500 int @
int = value.GetInt32(
"Version");
1501 int int2 = value.GetInt32(
"HashSize");
1505 buckets =
new int[int2];
1506 for (
int i = 0; i < buckets.Length; i++)
1510 entries =
new Entry[int2];
1515 ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
1517 for (
int j = 0; j < array.Length; j++)
1519 if (array[j].Key ==
null)
1521 ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullKey);
1523 Insert(array[j].Key, array[j].Value, add:
true);
1531 HashHelpers.SerializationInfoTable.Remove(
this);
1534 private void Resize()
1536 Resize(HashHelpers.ExpandPrime(count), forceNewHashCodes:
false);
1539 private void Resize(
int newSize,
bool forceNewHashCodes)
1541 int[] array =
new int[newSize];
1542 for (
int i = 0; i < array.Length; i++)
1546 Entry[] array2 =
new Entry[newSize];
1547 Array.
Copy(entries, 0, array2, 0, count);
1548 if (forceNewHashCodes)
1550 for (
int j = 0; j < count; j++)
1552 if (array2[j].hashCode != -1)
1554 array2[j].hashCode = (comparer.GetHashCode(array2[j].key) &
int.MaxValue);
1558 for (
int k = 0; k < count; k++)
1560 if (array2[k].hashCode >= 0)
1562 int num = array2[k].hashCode % newSize;
1563 array2[k].next = array[num];
1577 [__DynamicallyInvokable]
1582 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1584 if (buckets !=
null)
1586 int num = comparer.GetHashCode(key) &
int.MaxValue;
1587 int num2 = num % buckets.Length;
1589 for (
int num4 = buckets[num2]; num4 >= 0; num4 = entries[num4].next)
1591 if (entries[num4].hashCode == num && comparer.Equals(entries[num4].key, key))
1595 buckets[num2] = entries[num4].next;
1599 entries[num3].next = entries[num4].next;
1601 entries[num4].hashCode = -1;
1602 entries[num4].next = freeList;
1603 entries[num4].key =
default(TKey);
1604 entries[num4].value =
default(TValue);
1623 [__DynamicallyInvokable]
1626 int num = FindEntry(key);
1629 value = entries[num].value;
1632 value =
default(TValue);
1636 internal TValue GetValueOrDefault(TKey key)
1638 int num = FindEntry(key);
1641 return entries[num].value;
1643 return default(TValue);
1646 [__DynamicallyInvokable]
1647 void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array,
int index)
1649 CopyTo(array, index);
1662 [__DynamicallyInvokable]
1663 void ICollection.CopyTo(Array array,
int index)
1667 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
1669 if (array.Rank != 1)
1671 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
1673 if (array.GetLowerBound(0) != 0)
1675 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
1677 if (index < 0 || index > array.Length)
1679 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
1681 if (array.Length - index <
Count)
1683 ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
1685 KeyValuePair<TKey, TValue>[] array2 = array as KeyValuePair<TKey, TValue>[];
1688 CopyTo(array2, index);
1690 else if (array is DictionaryEntry[])
1692 DictionaryEntry[] array3 = array as DictionaryEntry[];
1693 Entry[] array4 = entries;
1694 for (
int i = 0; i < count; i++)
1696 if (array4[i].hashCode >= 0)
1698 array3[index++] =
new DictionaryEntry(array4[i].key, array4[i].value);
1704 object[] array5 = array as
object[];
1707 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
1712 Entry[] array6 = entries;
1713 for (
int j = 0; j < num2; j++)
1715 if (array6[j].hashCode >= 0)
1717 array5[index++] =
new KeyValuePair<TKey, TValue>(array6[j].key, array6[j].value);
1721 catch (ArrayTypeMismatchException)
1723 ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
1730 [__DynamicallyInvokable]
1731 IEnumerator IEnumerable.GetEnumerator()
1733 return new Enumerator(
this, 2);
1736 private static bool IsCompatibleKey(
object key)
1740 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1753 [__DynamicallyInvokable]
1754 void IDictionary.Add(
object key,
object value)
1758 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1760 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<TValue>(value, ExceptionArgument.value);
1763 TKey key2 = (TKey)key;
1766 Add(key2, (TValue)value);
1768 catch (InvalidCastException)
1770 ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
1773 catch (InvalidCastException)
1775 ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
1785 [__DynamicallyInvokable]
1786 bool IDictionary.Contains(
object key)
1788 if (IsCompatibleKey(key))
1797 [__DynamicallyInvokable]
1798 IDictionaryEnumerator IDictionary.GetEnumerator()
1800 return new Enumerator(
this, 1);
1807 [__DynamicallyInvokable]
1808 void IDictionary.Remove(
object key)
1810 if (IsCompatibleKey(key))
bool Remove(TKey key)
Removes the value with the specified key from the T:System.Collections.Generic.Dictionary`2.
Enumerates the elements of a T:System.Collections.Generic.Dictionary`2.
Represents the collection of values in a T:System.Collections.Generic.Dictionary`2....
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
Defines methods to support the comparison of objects for equality.
TValue Value
Gets the value in the key/value pair.
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Implements the T:System.Runtime.Serialization.ISerializable interface and returns the data needed to ...
void Reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
int Count
Gets the number of elements contained in the T:System.Collections.Generic.Dictionary`2....
static void Clear(Array array, int index, int length)
Sets a range of elements in an array to the default value of each element type.
Enumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Generic.Dictionary`2....
object Key
Gets the key of the current dictionary entry.
void CopyTo(TKey[] array, int index)
Copies the T:System.Collections.Generic.Dictionary`2.KeyCollection elements to an existing one-dimens...
bool MoveNext()
Advances the enumerator to the next element of the T:System.Collections.Generic.Dictionary`2....
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
bool ContainsValue(TValue value)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains a specific value.
Dictionary(int capacity, IEqualityComparer< TKey > comparer)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
new IEnumerator< T > GetEnumerator()
Returns an enumerator that iterates through the collection.
bool MoveNext()
Advances the enumerator to the next element of the T:System.Collections.Generic.Dictionary`2.
bool Remove(T item)
Removes the first occurrence of a specific object from the T:System.Collections.Generic....
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
Dictionary(int capacity)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Represents a strongly-typed, read-only collection of elements.
TValue Current
Gets the element at the current position of the enumerator.
Enumerates the elements of a T:System.Collections.Generic.Dictionary`2.ValueCollection.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
KeyCollection(Dictionary< TKey, TValue > dictionary)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2.KeyCollection class that ...
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
bool ContainsKey(TKey key)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains the specified key.
Supports a simple iteration over a generic collection.
Defines methods to manipulate generic collections.
Enumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Generic.Dictionary`2....
Defines a key/value pair that can be set or retrieved.
ValueCollection Values
Gets a collection containing the values in the T:System.Collections.Generic.Dictionary`2.
TKey Key
Gets the key in the key/value pair.
void Dispose()
Releases all resources used by the T:System.Collections.Generic.Dictionary`2.Enumerator.
KeyCollection Keys
Gets a collection containing the keys in the T:System.Collections.Generic.Dictionary`2.
Represents a generic collection of key/value pairs.
int Count
Gets the number of elements contained in the T:System.Collections.Generic.Dictionary`2....
int Count
Gets the number of key/value pairs contained in the T:System.Collections.Generic.Dictionary`2.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
bool IsReadOnly
Gets a value indicating whether the T:System.Collections.Generic.ICollection`1 is read-only.
Dictionary(IDictionary< TKey, TValue > dictionary)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that contains eleme...
Dictionary()
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.ICollection is synchronized (threa...
KeyValuePair< TKey, TValue > Current
Gets the element at the current position of the enumerator.
new T Current
Gets the element in the collection at the current position of the enumerator.
Enumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Generic.Dictionary`2.
Represents a generic read-only collection of key/value pairs.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
ICollection Keys
Gets an T:System.Collections.ICollection object containing the keys of the T:System....
ICollection Values
Gets an T:System.Collections.ICollection object containing the values in the T:System....
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
void Dispose()
Releases all resources used by the T:System.Collections.Generic.Dictionary`2.ValueCollection....
Allows an object to control its own serialization and deserialization.
ValueCollection(Dictionary< TKey, TValue > dictionary)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2.ValueCollection class tha...
DictionaryEntry Entry
Gets both the key and the value of the current dictionary entry.
TKey Current
Gets the element at the current position of the enumerator.
void CopyTo(TValue[] array, int index)
Copies the T:System.Collections.Generic.Dictionary`2.ValueCollection elements to an existing one-dime...
object Value
Gets the value of the current dictionary entry.
Specifies that the class can be serialized.
Enumerates the elements of a nongeneric dictionary.
void Add(TKey key, TValue value)
Adds the specified key and value to the dictionary.
bool MoveNext()
Advances the enumerator to the next element of the T:System.Collections.Generic.Dictionary`2....
virtual void OnDeserialization(object sender)
Implements the T:System.Runtime.Serialization.ISerializable interface and raises the deserialization ...
Dictionary(IEqualityComparer< TKey > comparer)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Dictionary(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class with serialized dat...
Enumerates the elements of a T:System.Collections.Generic.Dictionary`2.KeyCollection.
Defines a dictionary key/value pair that can be set or retrieved.
IEqualityComparer< TKey > Comparer
Gets the T:System.Collections.Generic.IEqualityComparer`1 that is used to determine equality of keys ...
Represents the collection of keys in a T:System.Collections.Generic.Dictionary`2. This class cannot b...
void Clear()
Removes all keys and values from the T:System.Collections.Generic.Dictionary`2.
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Provides atomic operations for variables that are shared by multiple threads.
void Dispose()
Releases all resources used by the T:System.Collections.Generic.Dictionary`2.KeyCollection....
The default setting for this enumeration, which is currently F:System.GCCollectionMode....
void Add(T item)
Adds an item to the T:System.Collections.Generic.ICollection`1.
void Clear()
Removes all items from the T:System.Collections.Generic.ICollection`1.