mscorlib(4.0.0.0) API with additions
Dictionary.cs
1 using System.Diagnostics;
4 using System.Security;
5 using System.Threading;
6 
8 {
12  [Serializable]
13  [DebuggerTypeProxy(typeof(Mscorlib_DictionaryDebugView<, >))]
14  [DebuggerDisplay("Count = {Count}")]
15  [ComVisible(false)]
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
18  {
19  private struct Entry
20  {
21  public int hashCode;
22 
23  public int next;
24 
25  public TKey key;
26 
27  public TValue value;
28  }
29 
31  [Serializable]
32  [__DynamicallyInvokable]
33  public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposable, IEnumerator, IDictionaryEnumerator
34  {
35  private Dictionary<TKey, TValue> dictionary;
36 
37  private int version;
38 
39  private int index;
40 
41  private KeyValuePair<TKey, TValue> current;
42 
43  private int getEnumeratorRetType;
44 
45  internal const int DictEntry = 1;
46 
47  internal const int KeyValuePair = 2;
48 
51  [__DynamicallyInvokable]
53  {
54  [__DynamicallyInvokable]
55  get
56  {
57  return current;
58  }
59  }
60 
64  [__DynamicallyInvokable]
65  object IEnumerator.Current
66  {
67  [__DynamicallyInvokable]
68  get
69  {
70  if (index == 0 || index == dictionary.count + 1)
71  {
72  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
73  }
74  if (getEnumeratorRetType == 1)
75  {
76  return new DictionaryEntry(current.Key, current.Value);
77  }
78  return new KeyValuePair<TKey, TValue>(current.Key, current.Value);
79  }
80  }
81 
85  [__DynamicallyInvokable]
87  {
88  [__DynamicallyInvokable]
89  get
90  {
91  if (index == 0 || index == dictionary.count + 1)
92  {
93  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
94  }
95  return new DictionaryEntry(current.Key, current.Value);
96  }
97  }
98 
102  [__DynamicallyInvokable]
104  {
105  [__DynamicallyInvokable]
106  get
107  {
108  if (index == 0 || index == dictionary.count + 1)
109  {
110  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
111  }
112  return current.Key;
113  }
114  }
115 
119  [__DynamicallyInvokable]
121  {
122  [__DynamicallyInvokable]
123  get
124  {
125  if (index == 0 || index == dictionary.count + 1)
126  {
127  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
128  }
129  return current.Value;
130  }
131  }
132 
133  internal Enumerator(Dictionary<TKey, TValue> dictionary, int getEnumeratorRetType)
134  {
135  this.dictionary = dictionary;
136  version = dictionary.version;
137  index = 0;
138  this.getEnumeratorRetType = getEnumeratorRetType;
139  current = default(KeyValuePair<TKey, TValue>);
140  }
141 
146  [__DynamicallyInvokable]
147  public bool MoveNext()
148  {
149  if (version != dictionary.version)
150  {
151  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
152  }
153  while ((uint)index < (uint)dictionary.count)
154  {
155  if (dictionary.entries[index].hashCode >= 0)
156  {
157  current = new KeyValuePair<TKey, TValue>(dictionary.entries[index].key, dictionary.entries[index].value);
158  index++;
159  return true;
160  }
161  index++;
162  }
163  index = dictionary.count + 1;
164  current = default(KeyValuePair<TKey, TValue>);
165  return false;
166  }
167 
169  [__DynamicallyInvokable]
170  public void Dispose()
171  {
172  }
173 
176  [__DynamicallyInvokable]
178  {
179  if (version != dictionary.version)
180  {
181  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
182  }
183  index = 0;
184  current = default(KeyValuePair<TKey, TValue>);
185  }
186  }
187 
189  [Serializable]
190  [DebuggerTypeProxy(typeof(Mscorlib_DictionaryKeyCollectionDebugView<, >))]
191  [DebuggerDisplay("Count = {Count}")]
192  [__DynamicallyInvokable]
194  {
196  [Serializable]
197  [__DynamicallyInvokable]
199  {
200  private Dictionary<TKey, TValue> dictionary;
201 
202  private int index;
203 
204  private int version;
205 
206  private TKey currentKey;
207 
210  [__DynamicallyInvokable]
211  public TKey Current
212  {
213  [__DynamicallyInvokable]
214  get
215  {
216  return currentKey;
217  }
218  }
219 
223  [__DynamicallyInvokable]
224  object IEnumerator.Current
225  {
226  [__DynamicallyInvokable]
227  get
228  {
229  if (index == 0 || index == dictionary.count + 1)
230  {
231  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
232  }
233  return currentKey;
234  }
235  }
236 
237  internal Enumerator(Dictionary<TKey, TValue> dictionary)
238  {
239  this.dictionary = dictionary;
240  version = dictionary.version;
241  index = 0;
242  currentKey = default(TKey);
243  }
244 
246  [__DynamicallyInvokable]
247  public void Dispose()
248  {
249  }
250 
255  [__DynamicallyInvokable]
256  public bool MoveNext()
257  {
258  if (version != dictionary.version)
259  {
260  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
261  }
262  while ((uint)index < (uint)dictionary.count)
263  {
264  if (dictionary.entries[index].hashCode >= 0)
265  {
266  currentKey = dictionary.entries[index].key;
267  index++;
268  return true;
269  }
270  index++;
271  }
272  index = dictionary.count + 1;
273  currentKey = default(TKey);
274  return false;
275  }
276 
279  [__DynamicallyInvokable]
281  {
282  if (version != dictionary.version)
283  {
284  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
285  }
286  index = 0;
287  currentKey = default(TKey);
288  }
289  }
290 
291  private Dictionary<TKey, TValue> dictionary;
292 
295  [__DynamicallyInvokable]
296  public int Count
297  {
298  [__DynamicallyInvokable]
299  get
300  {
301  return dictionary.Count;
302  }
303  }
304 
308  [__DynamicallyInvokable]
310  {
311  [__DynamicallyInvokable]
312  get
313  {
314  return true;
315  }
316  }
317 
321  [__DynamicallyInvokable]
323  {
324  [__DynamicallyInvokable]
325  get
326  {
327  return false;
328  }
329  }
330 
333  [__DynamicallyInvokable]
334  object ICollection.SyncRoot
335  {
336  [__DynamicallyInvokable]
337  get
338  {
339  return ((ICollection)dictionary).SyncRoot;
340  }
341  }
342 
347  [__DynamicallyInvokable]
349  {
350  if (dictionary == null)
351  {
352  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
353  }
354  this.dictionary = dictionary;
355  }
356 
359  [__DynamicallyInvokable]
361  {
362  return new Enumerator(dictionary);
363  }
364 
373  [__DynamicallyInvokable]
374  public void CopyTo(TKey[] array, int index)
375  {
376  if (array == null)
377  {
378  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
379  }
380  if (index < 0 || index > array.Length)
381  {
382  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
383  }
384  if (array.Length - index < dictionary.Count)
385  {
386  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
387  }
388  int count = dictionary.count;
389  Entry[] entries = dictionary.entries;
390  for (int i = 0; i < count; i++)
391  {
392  if (entries[i].hashCode >= 0)
393  {
394  array[index++] = entries[i].key;
395  }
396  }
397  }
398 
402  [__DynamicallyInvokable]
403  void ICollection<TKey>.Add(TKey item)
404  {
405  ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
406  }
407 
410  [__DynamicallyInvokable]
411  void ICollection<TKey>.Clear()
412  {
413  ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
414  }
415 
420  [__DynamicallyInvokable]
421  bool ICollection<TKey>.Contains(TKey item)
422  {
423  return dictionary.ContainsKey(item);
424  }
425 
431  [__DynamicallyInvokable]
432  bool ICollection<TKey>.Remove(TKey item)
433  {
434  ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_KeyCollectionSet);
435  return false;
436  }
437 
440  [__DynamicallyInvokable]
441  IEnumerator<TKey> IEnumerable<TKey>.GetEnumerator()
442  {
443  return new Enumerator(dictionary);
444  }
445 
448  [__DynamicallyInvokable]
449  IEnumerator IEnumerable.GetEnumerator()
450  {
451  return new Enumerator(dictionary);
452  }
453 
464  [__DynamicallyInvokable]
465  void ICollection.CopyTo(Array array, int index)
466  {
467  if (array == null)
468  {
469  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
470  }
471  if (array.Rank != 1)
472  {
473  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
474  }
475  if (array.GetLowerBound(0) != 0)
476  {
477  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
478  }
479  if (index < 0 || index > array.Length)
480  {
481  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
482  }
483  if (array.Length - index < dictionary.Count)
484  {
485  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
486  }
487  TKey[] array2 = array as TKey[];
488  if (array2 != null)
489  {
490  CopyTo(array2, index);
491  return;
492  }
493  object[] array3 = array as object[];
494  if (array3 == null)
495  {
496  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
497  }
498  int count = dictionary.count;
499  Entry[] entries = dictionary.entries;
500  try
501  {
502  for (int i = 0; i < count; i++)
503  {
504  if (entries[i].hashCode >= 0)
505  {
506  array3[index++] = entries[i].key;
507  }
508  }
509  }
510  catch (ArrayTypeMismatchException)
511  {
512  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
513  }
514  }
515  }
516 
518  [Serializable]
519  [DebuggerTypeProxy(typeof(Mscorlib_DictionaryValueCollectionDebugView<, >))]
520  [DebuggerDisplay("Count = {Count}")]
521  [__DynamicallyInvokable]
522  public sealed class ValueCollection : ICollection<TValue>, IEnumerable<TValue>, IEnumerable, ICollection, IReadOnlyCollection<TValue>
523  {
525  [Serializable]
526  [__DynamicallyInvokable]
527  public struct Enumerator : IEnumerator<TValue>, IDisposable, IEnumerator
528  {
529  private Dictionary<TKey, TValue> dictionary;
530 
531  private int index;
532 
533  private int version;
534 
535  private TValue currentValue;
536 
539  [__DynamicallyInvokable]
540  public TValue Current
541  {
542  [__DynamicallyInvokable]
543  get
544  {
545  return currentValue;
546  }
547  }
548 
552  [__DynamicallyInvokable]
553  object IEnumerator.Current
554  {
555  [__DynamicallyInvokable]
556  get
557  {
558  if (index == 0 || index == dictionary.count + 1)
559  {
560  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen);
561  }
562  return currentValue;
563  }
564  }
565 
566  internal Enumerator(Dictionary<TKey, TValue> dictionary)
567  {
568  this.dictionary = dictionary;
569  version = dictionary.version;
570  index = 0;
571  currentValue = default(TValue);
572  }
573 
575  [__DynamicallyInvokable]
576  public void Dispose()
577  {
578  }
579 
584  [__DynamicallyInvokable]
585  public bool MoveNext()
586  {
587  if (version != dictionary.version)
588  {
589  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
590  }
591  while ((uint)index < (uint)dictionary.count)
592  {
593  if (dictionary.entries[index].hashCode >= 0)
594  {
595  currentValue = dictionary.entries[index].value;
596  index++;
597  return true;
598  }
599  index++;
600  }
601  index = dictionary.count + 1;
602  currentValue = default(TValue);
603  return false;
604  }
605 
608  [__DynamicallyInvokable]
610  {
611  if (version != dictionary.version)
612  {
613  ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
614  }
615  index = 0;
616  currentValue = default(TValue);
617  }
618  }
619 
620  private Dictionary<TKey, TValue> dictionary;
621 
624  [__DynamicallyInvokable]
625  public int Count
626  {
627  [__DynamicallyInvokable]
628  get
629  {
630  return dictionary.Count;
631  }
632  }
633 
637  [__DynamicallyInvokable]
639  {
640  [__DynamicallyInvokable]
641  get
642  {
643  return true;
644  }
645  }
646 
650  [__DynamicallyInvokable]
652  {
653  [__DynamicallyInvokable]
654  get
655  {
656  return false;
657  }
658  }
659 
662  [__DynamicallyInvokable]
663  object ICollection.SyncRoot
664  {
665  [__DynamicallyInvokable]
666  get
667  {
668  return ((ICollection)dictionary).SyncRoot;
669  }
670  }
671 
676  [__DynamicallyInvokable]
678  {
679  if (dictionary == null)
680  {
681  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
682  }
683  this.dictionary = dictionary;
684  }
685 
688  [__DynamicallyInvokable]
690  {
691  return new Enumerator(dictionary);
692  }
693 
702  [__DynamicallyInvokable]
703  public void CopyTo(TValue[] array, int index)
704  {
705  if (array == null)
706  {
707  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
708  }
709  if (index < 0 || index > array.Length)
710  {
711  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
712  }
713  if (array.Length - index < dictionary.Count)
714  {
715  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
716  }
717  int count = dictionary.count;
718  Entry[] entries = dictionary.entries;
719  for (int i = 0; i < count; i++)
720  {
721  if (entries[i].hashCode >= 0)
722  {
723  array[index++] = entries[i].value;
724  }
725  }
726  }
727 
731  [__DynamicallyInvokable]
732  void ICollection<TValue>.Add(TValue item)
733  {
734  ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
735  }
736 
742  [__DynamicallyInvokable]
743  bool ICollection<TValue>.Remove(TValue item)
744  {
745  ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
746  return false;
747  }
748 
751  [__DynamicallyInvokable]
752  void ICollection<TValue>.Clear()
753  {
754  ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ValueCollectionSet);
755  }
756 
761  [__DynamicallyInvokable]
762  bool ICollection<TValue>.Contains(TValue item)
763  {
764  return dictionary.ContainsValue(item);
765  }
766 
769  [__DynamicallyInvokable]
770  IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator()
771  {
772  return new Enumerator(dictionary);
773  }
774 
777  [__DynamicallyInvokable]
778  IEnumerator IEnumerable.GetEnumerator()
779  {
780  return new Enumerator(dictionary);
781  }
782 
793  [__DynamicallyInvokable]
794  void ICollection.CopyTo(Array array, int index)
795  {
796  if (array == null)
797  {
798  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
799  }
800  if (array.Rank != 1)
801  {
802  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
803  }
804  if (array.GetLowerBound(0) != 0)
805  {
806  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
807  }
808  if (index < 0 || index > array.Length)
809  {
810  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
811  }
812  if (array.Length - index < dictionary.Count)
813  {
814  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
815  }
816  TValue[] array2 = array as TValue[];
817  if (array2 != null)
818  {
819  CopyTo(array2, index);
820  return;
821  }
822  object[] array3 = array as object[];
823  if (array3 == null)
824  {
825  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
826  }
827  int count = dictionary.count;
828  Entry[] entries = dictionary.entries;
829  try
830  {
831  for (int i = 0; i < count; i++)
832  {
833  if (entries[i].hashCode >= 0)
834  {
835  array3[index++] = entries[i].value;
836  }
837  }
838  }
839  catch (ArrayTypeMismatchException)
840  {
841  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
842  }
843  }
844  }
845 
846  private int[] buckets;
847 
848  private Entry[] entries;
849 
850  private int count;
851 
852  private int version;
853 
854  private int freeList;
855 
856  private int freeCount;
857 
858  private IEqualityComparer<TKey> comparer;
859 
860  private KeyCollection keys;
861 
862  private ValueCollection values;
863 
864  private object _syncRoot;
865 
866  private const string VersionName = "Version";
867 
868  private const string HashSizeName = "HashSize";
869 
870  private const string KeyValuePairsName = "KeyValuePairs";
871 
872  private const string ComparerName = "Comparer";
873 
876  [__DynamicallyInvokable]
877  public IEqualityComparer<TKey> Comparer
878  {
879  [__DynamicallyInvokable]
880  get
881  {
882  return comparer;
883  }
884  }
885 
888  [__DynamicallyInvokable]
889  public int Count
890  {
891  [__DynamicallyInvokable]
892  get
893  {
894  return count - freeCount;
895  }
896  }
897 
900  [__DynamicallyInvokable]
901  public KeyCollection Keys
902  {
903  [__DynamicallyInvokable]
904  get
905  {
906  if (keys == null)
907  {
908  keys = new KeyCollection(this);
909  }
910  return keys;
911  }
912  }
913 
914  [__DynamicallyInvokable]
916  {
917  [__DynamicallyInvokable]
918  get
919  {
920  if (keys == null)
921  {
922  keys = new KeyCollection(this);
923  }
924  return keys;
925  }
926  }
927 
928  [__DynamicallyInvokable]
929  IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys
930  {
931  [__DynamicallyInvokable]
932  get
933  {
934  if (keys == null)
935  {
936  keys = new KeyCollection(this);
937  }
938  return keys;
939  }
940  }
941 
944  [__DynamicallyInvokable]
945  public ValueCollection Values
946  {
947  [__DynamicallyInvokable]
948  get
949  {
950  if (values == null)
951  {
952  values = new ValueCollection(this);
953  }
954  return values;
955  }
956  }
957 
958  [__DynamicallyInvokable]
960  {
961  [__DynamicallyInvokable]
962  get
963  {
964  if (values == null)
965  {
966  values = new ValueCollection(this);
967  }
968  return values;
969  }
970  }
971 
972  [__DynamicallyInvokable]
973  IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values
974  {
975  [__DynamicallyInvokable]
976  get
977  {
978  if (values == null)
979  {
980  values = new ValueCollection(this);
981  }
982  return values;
983  }
984  }
985 
992  [__DynamicallyInvokable]
993  public TValue this[TKey key]
994  {
995  [__DynamicallyInvokable]
996  get
997  {
998  int num = FindEntry(key);
999  if (num >= 0)
1000  {
1001  return entries[num].value;
1002  }
1003  ThrowHelper.ThrowKeyNotFoundException();
1004  return default(TValue);
1005  }
1006  [__DynamicallyInvokable]
1007  set
1008  {
1009  Insert(key, value, add: false);
1010  }
1011  }
1012 
1013  [__DynamicallyInvokable]
1015  {
1016  [__DynamicallyInvokable]
1017  get
1018  {
1019  return false;
1020  }
1021  }
1022 
1026  [__DynamicallyInvokable]
1027  bool ICollection.IsSynchronized
1028  {
1029  [__DynamicallyInvokable]
1030  get
1031  {
1032  return false;
1033  }
1034  }
1035 
1038  [__DynamicallyInvokable]
1039  object ICollection.SyncRoot
1040  {
1041  [__DynamicallyInvokable]
1042  get
1043  {
1044  if (_syncRoot == null)
1045  {
1046  Interlocked.CompareExchange<object>(ref _syncRoot, new object(), (object)null);
1047  }
1048  return _syncRoot;
1049  }
1050  }
1051 
1055  [__DynamicallyInvokable]
1056  bool IDictionary.IsFixedSize
1057  {
1058  [__DynamicallyInvokable]
1059  get
1060  {
1061  return false;
1062  }
1063  }
1064 
1068  [__DynamicallyInvokable]
1069  bool IDictionary.IsReadOnly
1070  {
1071  [__DynamicallyInvokable]
1072  get
1073  {
1074  return false;
1075  }
1076  }
1077 
1080  [__DynamicallyInvokable]
1081  ICollection IDictionary.Keys
1082  {
1083  [__DynamicallyInvokable]
1084  get
1085  {
1086  return Keys;
1087  }
1088  }
1089 
1092  [__DynamicallyInvokable]
1093  ICollection IDictionary.Values
1094  {
1095  [__DynamicallyInvokable]
1096  get
1097  {
1098  return Values;
1099  }
1100  }
1101 
1109  [__DynamicallyInvokable]
1110  object IDictionary.this[object key]
1111  {
1112  [__DynamicallyInvokable]
1113  get
1114  {
1115  if (IsCompatibleKey(key))
1116  {
1117  int num = FindEntry((TKey)key);
1118  if (num >= 0)
1119  {
1120  return entries[num].value;
1121  }
1122  }
1123  return null;
1124  }
1125  [__DynamicallyInvokable]
1126  set
1127  {
1128  if (key == null)
1129  {
1130  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1131  }
1132  ThrowHelper.IfNullAndNullsAreIllegalThenThrow<TValue>(value, ExceptionArgument.value);
1133  try
1134  {
1135  TKey key2 = (TKey)key;
1136  try
1137  {
1138  this[key2] = (TValue)value;
1139  }
1140  catch (InvalidCastException)
1141  {
1142  ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
1143  }
1144  }
1145  catch (InvalidCastException)
1146  {
1147  ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
1148  }
1149  }
1150  }
1151 
1153  [__DynamicallyInvokable]
1154  public Dictionary()
1155  : this(0, (IEqualityComparer<TKey>)null)
1156  {
1157  }
1158 
1163  [__DynamicallyInvokable]
1164  public Dictionary(int capacity)
1165  : this(capacity, (IEqualityComparer<TKey>)null)
1166  {
1167  }
1168 
1171  [__DynamicallyInvokable]
1173  : this(0, comparer)
1174  {
1175  }
1176 
1182  [__DynamicallyInvokable]
1183  public Dictionary(int capacity, IEqualityComparer<TKey> comparer)
1184  {
1185  if (capacity < 0)
1186  {
1187  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
1188  }
1189  if (capacity > 0)
1190  {
1191  Initialize(capacity);
1192  }
1193  this.comparer = (comparer ?? EqualityComparer<TKey>.Default);
1194  }
1195 
1202  [__DynamicallyInvokable]
1204  : this(dictionary, (IEqualityComparer<TKey>)null)
1205  {
1206  }
1207 
1215  [__DynamicallyInvokable]
1217  : this((dictionary != null) ? dictionary.Count : 0, comparer)
1218  {
1219  if (dictionary == null)
1220  {
1221  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
1222  }
1223  foreach (KeyValuePair<TKey, TValue> item in dictionary)
1224  {
1225  Add(item.Key, item.Value);
1226  }
1227  }
1228 
1233  {
1234  HashHelpers.SerializationInfoTable.Add(this, info);
1235  }
1236 
1243  [__DynamicallyInvokable]
1244  public void Add(TKey key, TValue value)
1245  {
1246  Insert(key, value, add: true);
1247  }
1248 
1249  [__DynamicallyInvokable]
1251  {
1252  Add(keyValuePair.Key, keyValuePair.Value);
1253  }
1254 
1255  [__DynamicallyInvokable]
1256  bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> keyValuePair)
1257  {
1258  int num = FindEntry(keyValuePair.Key);
1259  if (num >= 0 && EqualityComparer<TValue>.Default.Equals(entries[num].value, keyValuePair.Value))
1260  {
1261  return true;
1262  }
1263  return false;
1264  }
1265 
1266  [__DynamicallyInvokable]
1267  bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> keyValuePair)
1268  {
1269  int num = FindEntry(keyValuePair.Key);
1270  if (num >= 0 && EqualityComparer<TValue>.Default.Equals(entries[num].value, keyValuePair.Value))
1271  {
1272  Remove(keyValuePair.Key);
1273  return true;
1274  }
1275  return false;
1276  }
1277 
1279  [__DynamicallyInvokable]
1280  public void Clear()
1281  {
1282  if (count > 0)
1283  {
1284  for (int i = 0; i < buckets.Length; i++)
1285  {
1286  buckets[i] = -1;
1287  }
1288  Array.Clear(entries, 0, count);
1289  freeList = -1;
1290  count = 0;
1291  freeCount = 0;
1292  version++;
1293  }
1294  }
1295 
1302  [__DynamicallyInvokable]
1303  public bool ContainsKey(TKey key)
1304  {
1305  return FindEntry(key) >= 0;
1306  }
1307 
1312  [__DynamicallyInvokable]
1313  public bool ContainsValue(TValue value)
1314  {
1315  if (value == null)
1316  {
1317  for (int i = 0; i < count; i++)
1318  {
1319  if (entries[i].hashCode >= 0 && entries[i].value == null)
1320  {
1321  return true;
1322  }
1323  }
1324  }
1325  else
1326  {
1328  for (int j = 0; j < count; j++)
1329  {
1330  if (entries[j].hashCode >= 0 && @default.Equals(entries[j].value, value))
1331  {
1332  return true;
1333  }
1334  }
1335  }
1336  return false;
1337  }
1338 
1339  private void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
1340  {
1341  if (array == null)
1342  {
1343  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
1344  }
1345  if (index < 0 || index > array.Length)
1346  {
1347  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
1348  }
1349  if (array.Length - index < Count)
1350  {
1351  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
1352  }
1353  int num = count;
1354  Entry[] array2 = entries;
1355  for (int i = 0; i < num; i++)
1356  {
1357  if (array2[i].hashCode >= 0)
1358  {
1359  array[index++] = new KeyValuePair<TKey, TValue>(array2[i].key, array2[i].value);
1360  }
1361  }
1362  }
1363 
1366  [__DynamicallyInvokable]
1367  public Enumerator GetEnumerator()
1368  {
1369  return new Enumerator(this, 2);
1370  }
1371 
1372  [__DynamicallyInvokable]
1374  {
1375  return new Enumerator(this, 2);
1376  }
1377 
1383  [SecurityCritical]
1384  public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
1385  {
1386  if (info == null)
1387  {
1388  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info);
1389  }
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)
1394  {
1396  CopyTo(array, 0);
1397  info.AddValue("KeyValuePairs", array, typeof(KeyValuePair<TKey, TValue>[]));
1398  }
1399  }
1400 
1401  private int FindEntry(TKey key)
1402  {
1403  if (key == null)
1404  {
1405  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1406  }
1407  if (buckets != null)
1408  {
1409  int num = comparer.GetHashCode(key) & int.MaxValue;
1410  for (int num2 = buckets[num % buckets.Length]; num2 >= 0; num2 = entries[num2].next)
1411  {
1412  if (entries[num2].hashCode == num && comparer.Equals(entries[num2].key, key))
1413  {
1414  return num2;
1415  }
1416  }
1417  }
1418  return -1;
1419  }
1420 
1421  private void Initialize(int capacity)
1422  {
1423  int prime = HashHelpers.GetPrime(capacity);
1424  buckets = new int[prime];
1425  for (int i = 0; i < buckets.Length; i++)
1426  {
1427  buckets[i] = -1;
1428  }
1429  entries = new Entry[prime];
1430  freeList = -1;
1431  }
1432 
1433  private void Insert(TKey key, TValue value, bool add)
1434  {
1435  if (key == null)
1436  {
1437  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1438  }
1439  if (buckets == null)
1440  {
1441  Initialize(0);
1442  }
1443  int num = comparer.GetHashCode(key) & int.MaxValue;
1444  int num2 = num % buckets.Length;
1445  int num3 = 0;
1446  for (int num4 = buckets[num2]; num4 >= 0; num4 = entries[num4].next)
1447  {
1448  if (entries[num4].hashCode == num && comparer.Equals(entries[num4].key, key))
1449  {
1450  if (add)
1451  {
1452  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate);
1453  }
1454  entries[num4].value = value;
1455  version++;
1456  return;
1457  }
1458  num3++;
1459  }
1460  int num5;
1461  if (freeCount > 0)
1462  {
1463  num5 = freeList;
1464  freeList = entries[num5].next;
1465  freeCount--;
1466  }
1467  else
1468  {
1469  if (count == entries.Length)
1470  {
1471  Resize();
1472  num2 = num % buckets.Length;
1473  }
1474  num5 = count;
1475  count++;
1476  }
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;
1482  version++;
1483  if (num3 > 100 && HashHelpers.IsWellKnownEqualityComparer(comparer))
1484  {
1485  comparer = (IEqualityComparer<TKey>)HashHelpers.GetRandomizedEqualityComparer(comparer);
1486  Resize(entries.Length, forceNewHashCodes: true);
1487  }
1488  }
1489 
1493  public virtual void OnDeserialization(object sender)
1494  {
1495  HashHelpers.SerializationInfoTable.TryGetValue(this, out SerializationInfo value);
1496  if (value == null)
1497  {
1498  return;
1499  }
1500  int @int = value.GetInt32("Version");
1501  int int2 = value.GetInt32("HashSize");
1502  comparer = (IEqualityComparer<TKey>)value.GetValue("Comparer", typeof(IEqualityComparer<TKey>));
1503  if (int2 != 0)
1504  {
1505  buckets = new int[int2];
1506  for (int i = 0; i < buckets.Length; i++)
1507  {
1508  buckets[i] = -1;
1509  }
1510  entries = new Entry[int2];
1511  freeList = -1;
1512  KeyValuePair<TKey, TValue>[] array = (KeyValuePair<TKey, TValue>[])value.GetValue("KeyValuePairs", typeof(KeyValuePair<TKey, TValue>[]));
1513  if (array == null)
1514  {
1515  ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
1516  }
1517  for (int j = 0; j < array.Length; j++)
1518  {
1519  if (array[j].Key == null)
1520  {
1521  ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullKey);
1522  }
1523  Insert(array[j].Key, array[j].Value, add: true);
1524  }
1525  }
1526  else
1527  {
1528  buckets = null;
1529  }
1530  version = @int;
1531  HashHelpers.SerializationInfoTable.Remove(this);
1532  }
1533 
1534  private void Resize()
1535  {
1536  Resize(HashHelpers.ExpandPrime(count), forceNewHashCodes: false);
1537  }
1538 
1539  private void Resize(int newSize, bool forceNewHashCodes)
1540  {
1541  int[] array = new int[newSize];
1542  for (int i = 0; i < array.Length; i++)
1543  {
1544  array[i] = -1;
1545  }
1546  Entry[] array2 = new Entry[newSize];
1547  Array.Copy(entries, 0, array2, 0, count);
1548  if (forceNewHashCodes)
1549  {
1550  for (int j = 0; j < count; j++)
1551  {
1552  if (array2[j].hashCode != -1)
1553  {
1554  array2[j].hashCode = (comparer.GetHashCode(array2[j].key) & int.MaxValue);
1555  }
1556  }
1557  }
1558  for (int k = 0; k < count; k++)
1559  {
1560  if (array2[k].hashCode >= 0)
1561  {
1562  int num = array2[k].hashCode % newSize;
1563  array2[k].next = array[num];
1564  array[num] = k;
1565  }
1566  }
1567  buckets = array;
1568  entries = array2;
1569  }
1570 
1577  [__DynamicallyInvokable]
1578  public bool Remove(TKey key)
1579  {
1580  if (key == null)
1581  {
1582  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1583  }
1584  if (buckets != null)
1585  {
1586  int num = comparer.GetHashCode(key) & int.MaxValue;
1587  int num2 = num % buckets.Length;
1588  int num3 = -1;
1589  for (int num4 = buckets[num2]; num4 >= 0; num4 = entries[num4].next)
1590  {
1591  if (entries[num4].hashCode == num && comparer.Equals(entries[num4].key, key))
1592  {
1593  if (num3 < 0)
1594  {
1595  buckets[num2] = entries[num4].next;
1596  }
1597  else
1598  {
1599  entries[num3].next = entries[num4].next;
1600  }
1601  entries[num4].hashCode = -1;
1602  entries[num4].next = freeList;
1603  entries[num4].key = default(TKey);
1604  entries[num4].value = default(TValue);
1605  freeList = num4;
1606  freeCount++;
1607  version++;
1608  return true;
1609  }
1610  num3 = num4;
1611  }
1612  }
1613  return false;
1614  }
1615 
1623  [__DynamicallyInvokable]
1624  public bool TryGetValue(TKey key, out TValue value)
1625  {
1626  int num = FindEntry(key);
1627  if (num >= 0)
1628  {
1629  value = entries[num].value;
1630  return true;
1631  }
1632  value = default(TValue);
1633  return false;
1634  }
1635 
1636  internal TValue GetValueOrDefault(TKey key)
1637  {
1638  int num = FindEntry(key);
1639  if (num >= 0)
1640  {
1641  return entries[num].value;
1642  }
1643  return default(TValue);
1644  }
1645 
1646  [__DynamicallyInvokable]
1647  void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
1648  {
1649  CopyTo(array, index);
1650  }
1651 
1662  [__DynamicallyInvokable]
1663  void ICollection.CopyTo(Array array, int index)
1664  {
1665  if (array == null)
1666  {
1667  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
1668  }
1669  if (array.Rank != 1)
1670  {
1671  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
1672  }
1673  if (array.GetLowerBound(0) != 0)
1674  {
1675  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
1676  }
1677  if (index < 0 || index > array.Length)
1678  {
1679  ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
1680  }
1681  if (array.Length - index < Count)
1682  {
1683  ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
1684  }
1685  KeyValuePair<TKey, TValue>[] array2 = array as KeyValuePair<TKey, TValue>[];
1686  if (array2 != null)
1687  {
1688  CopyTo(array2, index);
1689  }
1690  else if (array is DictionaryEntry[])
1691  {
1692  DictionaryEntry[] array3 = array as DictionaryEntry[];
1693  Entry[] array4 = entries;
1694  for (int i = 0; i < count; i++)
1695  {
1696  if (array4[i].hashCode >= 0)
1697  {
1698  array3[index++] = new DictionaryEntry(array4[i].key, array4[i].value);
1699  }
1700  }
1701  }
1702  else
1703  {
1704  object[] array5 = array as object[];
1705  if (array5 == null)
1706  {
1707  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
1708  }
1709  try
1710  {
1711  int num2 = count;
1712  Entry[] array6 = entries;
1713  for (int j = 0; j < num2; j++)
1714  {
1715  if (array6[j].hashCode >= 0)
1716  {
1717  array5[index++] = new KeyValuePair<TKey, TValue>(array6[j].key, array6[j].value);
1718  }
1719  }
1720  }
1721  catch (ArrayTypeMismatchException)
1722  {
1723  ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArrayType);
1724  }
1725  }
1726  }
1727 
1730  [__DynamicallyInvokable]
1731  IEnumerator IEnumerable.GetEnumerator()
1732  {
1733  return new Enumerator(this, 2);
1734  }
1735 
1736  private static bool IsCompatibleKey(object key)
1737  {
1738  if (key == null)
1739  {
1740  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1741  }
1742  return key is TKey;
1743  }
1744 
1753  [__DynamicallyInvokable]
1754  void IDictionary.Add(object key, object value)
1755  {
1756  if (key == null)
1757  {
1758  ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
1759  }
1760  ThrowHelper.IfNullAndNullsAreIllegalThenThrow<TValue>(value, ExceptionArgument.value);
1761  try
1762  {
1763  TKey key2 = (TKey)key;
1764  try
1765  {
1766  Add(key2, (TValue)value);
1767  }
1768  catch (InvalidCastException)
1769  {
1770  ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
1771  }
1772  }
1773  catch (InvalidCastException)
1774  {
1775  ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
1776  }
1777  }
1778 
1785  [__DynamicallyInvokable]
1786  bool IDictionary.Contains(object key)
1787  {
1788  if (IsCompatibleKey(key))
1789  {
1790  return ContainsKey((TKey)key);
1791  }
1792  return false;
1793  }
1794 
1797  [__DynamicallyInvokable]
1798  IDictionaryEnumerator IDictionary.GetEnumerator()
1799  {
1800  return new Enumerator(this, 1);
1801  }
1802 
1807  [__DynamicallyInvokable]
1808  void IDictionary.Remove(object key)
1809  {
1810  if (IsCompatibleKey(key))
1811  {
1812  Remove((TKey)key);
1813  }
1814  }
1815  }
1816 }
bool Remove(TKey key)
Removes the value with the specified key from the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:1578
Enumerates the elements of a T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:33
Represents the collection of values in a T:System.Collections.Generic.Dictionary`2....
Definition: Dictionary.cs:522
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.
Definition: KeyValuePair.cs:32
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Implements the T:System.Runtime.Serialization.ISerializable interface and returns the data needed to ...
Definition: Dictionary.cs:1384
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....
Definition: Dictionary.cs:626
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....
Definition: Dictionary.cs:360
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...
Definition: Dictionary.cs:374
bool MoveNext()
Advances the enumerator to the next element of the T:System.Collections.Generic.Dictionary`2....
Definition: Dictionary.cs:256
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
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.
Definition: Dictionary.cs:1313
Definition: __Canon.cs:3
Dictionary(int capacity, IEqualityComparer< TKey > comparer)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Definition: Dictionary.cs:1183
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.
Definition: Dictionary.cs:147
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....
Definition: IEnumerable.cs:9
Dictionary(int capacity)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Definition: Dictionary.cs:1164
Represents a strongly-typed, read-only collection of elements.
TValue Current
Gets the element at the current position of the enumerator.
Definition: Dictionary.cs:541
Enumerates the elements of a T:System.Collections.Generic.Dictionary`2.ValueCollection.
Definition: Dictionary.cs:527
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 ...
Definition: Dictionary.cs:348
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.
Definition: Dictionary.cs:1303
Supports a simple iteration over a generic collection.
Definition: IEnumerator.cs:6
Defines methods to manipulate generic collections.
Definition: ICollection.cs:9
Enumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Generic.Dictionary`2....
Definition: Dictionary.cs:689
Defines a key/value pair that can be set or retrieved.
Definition: KeyValuePair.cs:10
ValueCollection Values
Gets a collection containing the values in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:946
TKey Key
Gets the key in the key/value pair.
Definition: KeyValuePair.cs:20
void Dispose()
Releases all resources used by the T:System.Collections.Generic.Dictionary`2.Enumerator.
Definition: Dictionary.cs:170
KeyCollection Keys
Gets a collection containing the keys in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:902
Represents a generic collection of key/value pairs.
Definition: IDictionary.cs:7
int Count
Gets the number of elements contained in the T:System.Collections.Generic.Dictionary`2....
Definition: Dictionary.cs:297
int Count
Gets the number of key/value pairs contained in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:890
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.
Definition: ICollection.cs:25
Dictionary(IDictionary< TKey, TValue > dictionary)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that contains eleme...
Definition: Dictionary.cs:1203
Dictionary()
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Definition: Dictionary.cs:1154
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.ICollection is synchronized (threa...
Definition: ICollection.cs:33
KeyValuePair< TKey, TValue > Current
Gets the element at the current position of the enumerator.
Definition: Dictionary.cs:53
new T Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:12
Enumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:1367
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,...
Definition: Dictionary.cs:17
ICollection Keys
Gets an T:System.Collections.ICollection object containing the keys of the T:System....
Definition: IDictionary.cs:29
ICollection Values
Gets an T:System.Collections.ICollection object containing the values in the T:System....
Definition: IDictionary.cs:38
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 ...
Definition: Array.cs:1275
void Dispose()
Releases all resources used by the T:System.Collections.Generic.Dictionary`2.ValueCollection....
Definition: Dictionary.cs:576
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
ValueCollection(Dictionary< TKey, TValue > dictionary)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2.ValueCollection class tha...
Definition: Dictionary.cs:677
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.
Definition: Dictionary.cs:212
void CopyTo(TValue[] array, int index)
Copies the T:System.Collections.Generic.Dictionary`2.ValueCollection elements to an existing one-dime...
Definition: Dictionary.cs:703
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.
Definition: Dictionary.cs:1244
bool MoveNext()
Advances the enumerator to the next element of the T:System.Collections.Generic.Dictionary`2....
Definition: Dictionary.cs:585
virtual void OnDeserialization(object sender)
Implements the T:System.Runtime.Serialization.ISerializable interface and raises the deserialization ...
Definition: Dictionary.cs:1493
Dictionary(IEqualityComparer< TKey > comparer)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class that is empty,...
Definition: Dictionary.cs:1172
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
Dictionary(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.Collections.Generic.Dictionary`2 class with serialized dat...
Definition: Dictionary.cs:1232
Enumerates the elements of a T:System.Collections.Generic.Dictionary`2.KeyCollection.
Definition: Dictionary.cs:198
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 ...
Definition: Dictionary.cs:878
Represents the collection of keys in a T:System.Collections.Generic.Dictionary`2. This class cannot b...
Definition: Dictionary.cs:193
void Clear()
Removes all keys and values from the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:1280
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Definition: Dictionary.cs:1624
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
void Dispose()
Releases all resources used by the T:System.Collections.Generic.Dictionary`2.KeyCollection....
Definition: Dictionary.cs:247
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.