mscorlib(4.0.0.0) API with additions
Array.cs
1 using System.Collections;
8 using System.Security;
10 
11 namespace System
12 {
14  [Serializable]
15  [ComVisible(true)]
16  [__DynamicallyInvokable]
18  {
19  internal sealed class FunctorComparer<T> : IComparer<T>
20  {
21  private Comparison<T> comparison;
22 
23  public FunctorComparer(Comparison<T> comparison)
24  {
25  this.comparison = comparison;
26  }
27 
28  public int Compare(T x, T y)
29  {
30  return comparison(x, y);
31  }
32  }
33 
34  private struct SorterObjectArray
35  {
36  private object[] keys;
37 
38  private object[] items;
39 
40  private IComparer comparer;
41 
42  internal SorterObjectArray(object[] keys, object[] items, IComparer comparer)
43  {
44  if (comparer == null)
45  {
46  comparer = Comparer.Default;
47  }
48  this.keys = keys;
49  this.items = items;
50  this.comparer = comparer;
51  }
52 
53  internal void SwapIfGreaterWithItems(int a, int b)
54  {
55  if (a != b && comparer.Compare(keys[a], keys[b]) > 0)
56  {
57  object obj = keys[a];
58  keys[a] = keys[b];
59  keys[b] = obj;
60  if (items != null)
61  {
62  object obj2 = items[a];
63  items[a] = items[b];
64  items[b] = obj2;
65  }
66  }
67  }
68 
69  private void Swap(int i, int j)
70  {
71  object obj = keys[i];
72  keys[i] = keys[j];
73  keys[j] = obj;
74  if (items != null)
75  {
76  object obj2 = items[i];
77  items[i] = items[j];
78  items[j] = obj2;
79  }
80  }
81 
82  internal void Sort(int left, int length)
83  {
84  if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
85  {
86  IntrospectiveSort(left, length);
87  }
88  else
89  {
90  DepthLimitedQuickSort(left, length + left - 1, 32);
91  }
92  }
93 
94  private void DepthLimitedQuickSort(int left, int right, int depthLimit)
95  {
96  while (depthLimit != 0)
97  {
98  int i = left;
99  int num = right;
100  int median = GetMedian(i, num);
101  try
102  {
103  SwapIfGreaterWithItems(i, median);
104  SwapIfGreaterWithItems(i, num);
105  SwapIfGreaterWithItems(median, num);
106  }
107  catch (Exception innerException)
108  {
109  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
110  }
111  object obj = keys[median];
112  do
113  {
114  try
115  {
116  for (; comparer.Compare(keys[i], obj) < 0; i++)
117  {
118  }
119  while (comparer.Compare(obj, keys[num]) < 0)
120  {
121  num--;
122  }
123  }
125  {
126  throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
127  }
128  catch (Exception innerException2)
129  {
130  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException2);
131  }
132  if (i > num)
133  {
134  break;
135  }
136  if (i < num)
137  {
138  object obj2 = keys[i];
139  keys[i] = keys[num];
140  keys[num] = obj2;
141  if (items != null)
142  {
143  object obj3 = items[i];
144  items[i] = items[num];
145  items[num] = obj3;
146  }
147  }
148  i++;
149  num--;
150  }
151  while (i <= num);
152  depthLimit--;
153  if (num - left <= right - i)
154  {
155  if (left < num)
156  {
157  DepthLimitedQuickSort(left, num, depthLimit);
158  }
159  left = i;
160  }
161  else
162  {
163  if (i < right)
164  {
165  DepthLimitedQuickSort(i, right, depthLimit);
166  }
167  right = num;
168  }
169  if (left >= right)
170  {
171  return;
172  }
173  }
174  try
175  {
176  Heapsort(left, right);
177  }
179  {
180  throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
181  }
182  catch (Exception innerException3)
183  {
184  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException3);
185  }
186  }
187 
188  private void IntrospectiveSort(int left, int length)
189  {
190  if (length >= 2)
191  {
192  try
193  {
194  IntroSort(left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2(keys.Length));
195  }
197  {
198  IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
199  }
200  catch (Exception innerException)
201  {
202  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
203  }
204  }
205  }
206 
207  private void IntroSort(int lo, int hi, int depthLimit)
208  {
209  while (true)
210  {
211  if (hi <= lo)
212  {
213  return;
214  }
215  int num = hi - lo + 1;
216  if (num <= 16)
217  {
218  switch (num)
219  {
220  case 1:
221  break;
222  case 2:
223  SwapIfGreaterWithItems(lo, hi);
224  break;
225  case 3:
226  SwapIfGreaterWithItems(lo, hi - 1);
227  SwapIfGreaterWithItems(lo, hi);
228  SwapIfGreaterWithItems(hi - 1, hi);
229  break;
230  default:
231  InsertionSort(lo, hi);
232  break;
233  }
234  return;
235  }
236  if (depthLimit == 0)
237  {
238  break;
239  }
240  depthLimit--;
241  int num2 = PickPivotAndPartition(lo, hi);
242  IntroSort(num2 + 1, hi, depthLimit);
243  hi = num2 - 1;
244  }
245  Heapsort(lo, hi);
246  }
247 
248  private int PickPivotAndPartition(int lo, int hi)
249  {
250  int num = lo + (hi - lo) / 2;
251  SwapIfGreaterWithItems(lo, num);
252  SwapIfGreaterWithItems(lo, hi);
253  SwapIfGreaterWithItems(num, hi);
254  object obj = keys[num];
255  Swap(num, hi - 1);
256  int num2 = lo;
257  int num3 = hi - 1;
258  while (num2 < num3)
259  {
260  while (comparer.Compare(keys[++num2], obj) < 0)
261  {
262  }
263  while (comparer.Compare(obj, keys[--num3]) < 0)
264  {
265  }
266  if (num2 >= num3)
267  {
268  break;
269  }
270  Swap(num2, num3);
271  }
272  Swap(num2, hi - 1);
273  return num2;
274  }
275 
276  private void Heapsort(int lo, int hi)
277  {
278  int num = hi - lo + 1;
279  for (int num2 = num / 2; num2 >= 1; num2--)
280  {
281  DownHeap(num2, num, lo);
282  }
283  for (int num3 = num; num3 > 1; num3--)
284  {
285  Swap(lo, lo + num3 - 1);
286  DownHeap(1, num3 - 1, lo);
287  }
288  }
289 
290  private void DownHeap(int i, int n, int lo)
291  {
292  object obj = keys[lo + i - 1];
293  object obj2 = (items != null) ? items[lo + i - 1] : null;
294  while (i <= n / 2)
295  {
296  int num = 2 * i;
297  if (num < n && comparer.Compare(keys[lo + num - 1], keys[lo + num]) < 0)
298  {
299  num++;
300  }
301  if (comparer.Compare(obj, keys[lo + num - 1]) >= 0)
302  {
303  break;
304  }
305  keys[lo + i - 1] = keys[lo + num - 1];
306  if (items != null)
307  {
308  items[lo + i - 1] = items[lo + num - 1];
309  }
310  i = num;
311  }
312  keys[lo + i - 1] = obj;
313  if (items != null)
314  {
315  items[lo + i - 1] = obj2;
316  }
317  }
318 
319  private void InsertionSort(int lo, int hi)
320  {
321  for (int i = lo; i < hi; i++)
322  {
323  int num = i;
324  object obj = keys[i + 1];
325  object obj2 = (items != null) ? items[i + 1] : null;
326  while (num >= lo && comparer.Compare(obj, keys[num]) < 0)
327  {
328  keys[num + 1] = keys[num];
329  if (items != null)
330  {
331  items[num + 1] = items[num];
332  }
333  num--;
334  }
335  keys[num + 1] = obj;
336  if (items != null)
337  {
338  items[num + 1] = obj2;
339  }
340  }
341  }
342  }
343 
344  private struct SorterGenericArray
345  {
346  private Array keys;
347 
348  private Array items;
349 
350  private IComparer comparer;
351 
352  internal SorterGenericArray(Array keys, Array items, IComparer comparer)
353  {
354  if (comparer == null)
355  {
356  comparer = Comparer.Default;
357  }
358  this.keys = keys;
359  this.items = items;
360  this.comparer = comparer;
361  }
362 
363  internal void SwapIfGreaterWithItems(int a, int b)
364  {
365  if (a != b && comparer.Compare(keys.GetValue(a), keys.GetValue(b)) > 0)
366  {
367  object value = keys.GetValue(a);
368  keys.SetValue(keys.GetValue(b), a);
369  keys.SetValue(value, b);
370  if (items != null)
371  {
372  object value2 = items.GetValue(a);
373  items.SetValue(items.GetValue(b), a);
374  items.SetValue(value2, b);
375  }
376  }
377  }
378 
379  private void Swap(int i, int j)
380  {
381  object value = keys.GetValue(i);
382  keys.SetValue(keys.GetValue(j), i);
383  keys.SetValue(value, j);
384  if (items != null)
385  {
386  object value2 = items.GetValue(i);
387  items.SetValue(items.GetValue(j), i);
388  items.SetValue(value2, j);
389  }
390  }
391 
392  internal void Sort(int left, int length)
393  {
394  if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
395  {
396  IntrospectiveSort(left, length);
397  }
398  else
399  {
400  DepthLimitedQuickSort(left, length + left - 1, 32);
401  }
402  }
403 
404  private void DepthLimitedQuickSort(int left, int right, int depthLimit)
405  {
406  while (depthLimit != 0)
407  {
408  int i = left;
409  int num = right;
410  int median = GetMedian(i, num);
411  try
412  {
413  SwapIfGreaterWithItems(i, median);
414  SwapIfGreaterWithItems(i, num);
415  SwapIfGreaterWithItems(median, num);
416  }
417  catch (Exception innerException)
418  {
419  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
420  }
421  object value = keys.GetValue(median);
422  do
423  {
424  try
425  {
426  for (; comparer.Compare(keys.GetValue(i), value) < 0; i++)
427  {
428  }
429  while (comparer.Compare(value, keys.GetValue(num)) < 0)
430  {
431  num--;
432  }
433  }
435  {
436  throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
437  }
438  catch (Exception innerException2)
439  {
440  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException2);
441  }
442  if (i > num)
443  {
444  break;
445  }
446  if (i < num)
447  {
448  object value2 = keys.GetValue(i);
449  keys.SetValue(keys.GetValue(num), i);
450  keys.SetValue(value2, num);
451  if (items != null)
452  {
453  object value3 = items.GetValue(i);
454  items.SetValue(items.GetValue(num), i);
455  items.SetValue(value3, num);
456  }
457  }
458  if (i != int.MaxValue)
459  {
460  i++;
461  }
462  if (num != int.MinValue)
463  {
464  num--;
465  }
466  }
467  while (i <= num);
468  depthLimit--;
469  if (num - left <= right - i)
470  {
471  if (left < num)
472  {
473  DepthLimitedQuickSort(left, num, depthLimit);
474  }
475  left = i;
476  }
477  else
478  {
479  if (i < right)
480  {
481  DepthLimitedQuickSort(i, right, depthLimit);
482  }
483  right = num;
484  }
485  if (left >= right)
486  {
487  return;
488  }
489  }
490  try
491  {
492  Heapsort(left, right);
493  }
495  {
496  throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
497  }
498  catch (Exception innerException3)
499  {
500  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException3);
501  }
502  }
503 
504  private void IntrospectiveSort(int left, int length)
505  {
506  if (length >= 2)
507  {
508  try
509  {
510  IntroSort(left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2(keys.Length));
511  }
513  {
514  IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
515  }
516  catch (Exception innerException)
517  {
518  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
519  }
520  }
521  }
522 
523  private void IntroSort(int lo, int hi, int depthLimit)
524  {
525  while (true)
526  {
527  if (hi <= lo)
528  {
529  return;
530  }
531  int num = hi - lo + 1;
532  if (num <= 16)
533  {
534  switch (num)
535  {
536  case 1:
537  break;
538  case 2:
539  SwapIfGreaterWithItems(lo, hi);
540  break;
541  case 3:
542  SwapIfGreaterWithItems(lo, hi - 1);
543  SwapIfGreaterWithItems(lo, hi);
544  SwapIfGreaterWithItems(hi - 1, hi);
545  break;
546  default:
547  InsertionSort(lo, hi);
548  break;
549  }
550  return;
551  }
552  if (depthLimit == 0)
553  {
554  break;
555  }
556  depthLimit--;
557  int num2 = PickPivotAndPartition(lo, hi);
558  IntroSort(num2 + 1, hi, depthLimit);
559  hi = num2 - 1;
560  }
561  Heapsort(lo, hi);
562  }
563 
564  private int PickPivotAndPartition(int lo, int hi)
565  {
566  int num = lo + (hi - lo) / 2;
567  SwapIfGreaterWithItems(lo, num);
568  SwapIfGreaterWithItems(lo, hi);
569  SwapIfGreaterWithItems(num, hi);
570  object value = keys.GetValue(num);
571  Swap(num, hi - 1);
572  int num2 = lo;
573  int num3 = hi - 1;
574  while (num2 < num3)
575  {
576  while (comparer.Compare(keys.GetValue(++num2), value) < 0)
577  {
578  }
579  while (comparer.Compare(value, keys.GetValue(--num3)) < 0)
580  {
581  }
582  if (num2 >= num3)
583  {
584  break;
585  }
586  Swap(num2, num3);
587  }
588  Swap(num2, hi - 1);
589  return num2;
590  }
591 
592  private void Heapsort(int lo, int hi)
593  {
594  int num = hi - lo + 1;
595  for (int num2 = num / 2; num2 >= 1; num2--)
596  {
597  DownHeap(num2, num, lo);
598  }
599  for (int num3 = num; num3 > 1; num3--)
600  {
601  Swap(lo, lo + num3 - 1);
602  DownHeap(1, num3 - 1, lo);
603  }
604  }
605 
606  private void DownHeap(int i, int n, int lo)
607  {
608  object value = keys.GetValue(lo + i - 1);
609  object value2 = (items != null) ? items.GetValue(lo + i - 1) : null;
610  while (i <= n / 2)
611  {
612  int num = 2 * i;
613  if (num < n && comparer.Compare(keys.GetValue(lo + num - 1), keys.GetValue(lo + num)) < 0)
614  {
615  num++;
616  }
617  if (comparer.Compare(value, keys.GetValue(lo + num - 1)) >= 0)
618  {
619  break;
620  }
621  keys.SetValue(keys.GetValue(lo + num - 1), lo + i - 1);
622  if (items != null)
623  {
624  items.SetValue(items.GetValue(lo + num - 1), lo + i - 1);
625  }
626  i = num;
627  }
628  keys.SetValue(value, lo + i - 1);
629  if (items != null)
630  {
631  items.SetValue(value2, lo + i - 1);
632  }
633  }
634 
635  private void InsertionSort(int lo, int hi)
636  {
637  for (int i = lo; i < hi; i++)
638  {
639  int num = i;
640  object value = keys.GetValue(i + 1);
641  object value2 = (items != null) ? items.GetValue(i + 1) : null;
642  while (num >= lo && comparer.Compare(value, keys.GetValue(num)) < 0)
643  {
644  keys.SetValue(keys.GetValue(num), num + 1);
645  if (items != null)
646  {
647  items.SetValue(items.GetValue(num), num + 1);
648  }
649  num--;
650  }
651  keys.SetValue(value, num + 1);
652  if (items != null)
653  {
654  items.SetValue(value2, num + 1);
655  }
656  }
657  }
658  }
659 
660  [Serializable]
661  private sealed class SZArrayEnumerator : IEnumerator, ICloneable
662  {
663  private Array _array;
664 
665  private int _index;
666 
667  private int _endIndex;
668 
669  public object Current
670  {
671  get
672  {
673  if (_index < 0)
674  {
675  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
676  }
677  if (_index >= _endIndex)
678  {
679  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
680  }
681  return _array.GetValue(_index);
682  }
683  }
684 
685  internal SZArrayEnumerator(Array array)
686  {
687  _array = array;
688  _index = -1;
689  _endIndex = array.Length;
690  }
691 
692  public object Clone()
693  {
694  return MemberwiseClone();
695  }
696 
697  public bool MoveNext()
698  {
699  if (_index < _endIndex)
700  {
701  _index++;
702  return _index < _endIndex;
703  }
704  return false;
705  }
706 
707  public void Reset()
708  {
709  _index = -1;
710  }
711  }
712 
713  [Serializable]
714  private sealed class ArrayEnumerator : IEnumerator, ICloneable
715  {
716  private Array array;
717 
718  private int index;
719 
720  private int endIndex;
721 
722  private int startIndex;
723 
724  private int[] _indices;
725 
726  private bool _complete;
727 
728  public object Current
729  {
730  get
731  {
732  if (index < startIndex)
733  {
734  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
735  }
736  if (_complete)
737  {
738  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
739  }
740  return array.GetValue(_indices);
741  }
742  }
743 
744  internal ArrayEnumerator(Array array, int index, int count)
745  {
746  this.array = array;
747  this.index = index - 1;
748  startIndex = index;
749  endIndex = index + count;
750  _indices = new int[array.Rank];
751  int num = 1;
752  for (int i = 0; i < array.Rank; i++)
753  {
754  _indices[i] = array.GetLowerBound(i);
755  num *= array.GetLength(i);
756  }
757  _indices[_indices.Length - 1]--;
758  _complete = (num == 0);
759  }
760 
761  private void IncArray()
762  {
763  int rank = array.Rank;
764  _indices[rank - 1]++;
765  int num = rank - 1;
766  while (true)
767  {
768  if (num < 0)
769  {
770  return;
771  }
772  if (_indices[num] > array.GetUpperBound(num))
773  {
774  if (num == 0)
775  {
776  break;
777  }
778  for (int i = num; i < rank; i++)
779  {
780  _indices[i] = array.GetLowerBound(i);
781  }
782  _indices[num - 1]++;
783  }
784  num--;
785  }
786  _complete = true;
787  }
788 
789  public object Clone()
790  {
791  return MemberwiseClone();
792  }
793 
794  public bool MoveNext()
795  {
796  if (_complete)
797  {
798  index = endIndex;
799  return false;
800  }
801  index++;
802  IncArray();
803  return !_complete;
804  }
805 
806  public void Reset()
807  {
808  index = startIndex - 1;
809  int num = 1;
810  for (int i = 0; i < array.Rank; i++)
811  {
812  _indices[i] = array.GetLowerBound(i);
813  num *= array.GetLength(i);
814  }
815  _complete = (num == 0);
816  _indices[_indices.Length - 1]--;
817  }
818  }
819 
820  internal const int MaxArrayLength = 2146435071;
821 
822  internal const int MaxByteArrayLength = 2147483591;
823 
827  [__DynamicallyInvokable]
828  public int Length
829  {
830  [MethodImpl(MethodImplOptions.InternalCall)]
831  [SecuritySafeCritical]
832  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
833  [__DynamicallyInvokable]
834  get;
835  }
836 
839  [ComVisible(false)]
840  public long LongLength
841  {
842  [MethodImpl(MethodImplOptions.InternalCall)]
843  [SecuritySafeCritical]
844  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
845  get;
846  }
847 
850  [__DynamicallyInvokable]
851  public int Rank
852  {
853  [MethodImpl(MethodImplOptions.InternalCall)]
854  [SecuritySafeCritical]
855  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
856  [__DynamicallyInvokable]
857  get;
858  }
859 
862  [__DynamicallyInvokable]
863  int ICollection.Count
864  {
865  [__DynamicallyInvokable]
866  get
867  {
868  return Length;
869  }
870  }
871 
874  public object SyncRoot => this;
875 
878  public bool IsReadOnly => false;
879 
882  public bool IsFixedSize => true;
883 
886  public bool IsSynchronized => false;
887 
895  [__DynamicallyInvokable]
896  object IList.this[int index]
897  {
898  [__DynamicallyInvokable]
899  get
900  {
901  return GetValue(index);
902  }
903  [__DynamicallyInvokable]
904  set
905  {
906  SetValue(value, index);
907  }
908  }
909 
910  internal Array()
911  {
912  }
913 
920  public static ReadOnlyCollection<T> AsReadOnly<T>(T[] array)
921  {
922  if (array == null)
923  {
924  throw new ArgumentNullException("array");
925  }
926  return new ReadOnlyCollection<T>(array);
927  }
928 
935  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
936  [__DynamicallyInvokable]
937  public static void Resize<T>(ref T[] array, int newSize)
938  {
939  if (newSize < 0)
940  {
941  throw new ArgumentOutOfRangeException("newSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
942  }
943  T[] array2 = array;
944  if (array2 == null)
945  {
946  array = new T[newSize];
947  }
948  else if (array2.Length != newSize)
949  {
950  T[] array3 = new T[newSize];
951  Copy(array2, 0, array3, 0, (array2.Length > newSize) ? newSize : array2.Length);
952  array = array3;
953  }
954  }
955 
970  [SecuritySafeCritical]
971  [__DynamicallyInvokable]
972  public unsafe static Array CreateInstance(Type elementType, int length)
973  {
974  if ((object)elementType == null)
975  {
976  throw new ArgumentNullException("elementType");
977  }
978  if (length < 0)
979  {
980  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
981  }
982  RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
983  if (runtimeType == null)
984  {
985  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
986  }
987  return InternalCreate((void*)runtimeType.TypeHandle.Value, 1, &length, null);
988  }
989 
1006  [SecuritySafeCritical]
1007  public unsafe static Array CreateInstance(Type elementType, int length1, int length2)
1008  {
1009  if ((object)elementType == null)
1010  {
1011  throw new ArgumentNullException("elementType");
1012  }
1013  if (length1 < 0 || length2 < 0)
1014  {
1015  throw new ArgumentOutOfRangeException((length1 < 0) ? "length1" : "length2", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1016  }
1017  RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
1018  if (runtimeType == null)
1019  {
1020  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
1021  }
1022  int* ptr = stackalloc int[2];
1023  *ptr = length1;
1024  ptr[1] = length2;
1025  return InternalCreate((void*)runtimeType.TypeHandle.Value, 2, ptr, null);
1026  }
1027 
1046  [SecuritySafeCritical]
1047  public unsafe static Array CreateInstance(Type elementType, int length1, int length2, int length3)
1048  {
1049  if ((object)elementType == null)
1050  {
1051  throw new ArgumentNullException("elementType");
1052  }
1053  if (length1 < 0)
1054  {
1055  throw new ArgumentOutOfRangeException("length1", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1056  }
1057  if (length2 < 0)
1058  {
1059  throw new ArgumentOutOfRangeException("length2", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1060  }
1061  if (length3 < 0)
1062  {
1063  throw new ArgumentOutOfRangeException("length3", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1064  }
1065  RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
1066  if (runtimeType == null)
1067  {
1068  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
1069  }
1070  int* ptr = stackalloc int[3];
1071  *ptr = length1;
1072  ptr[1] = length2;
1073  ptr[2] = length3;
1074  return InternalCreate((void*)runtimeType.TypeHandle.Value, 3, ptr, null);
1075  }
1076 
1091  [SecuritySafeCritical]
1092  [__DynamicallyInvokable]
1093  public unsafe static Array CreateInstance(Type elementType, params int[] lengths)
1094  {
1095  if ((object)elementType == null)
1096  {
1097  throw new ArgumentNullException("elementType");
1098  }
1099  if (lengths == null)
1100  {
1101  throw new ArgumentNullException("lengths");
1102  }
1103  if (lengths.Length == 0)
1104  {
1105  throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
1106  }
1107  RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
1108  if (runtimeType == null)
1109  {
1110  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
1111  }
1112  for (int i = 0; i < lengths.Length; i++)
1113  {
1114  if (lengths[i] < 0)
1115  {
1116  throw new ArgumentOutOfRangeException("lengths[" + i + "]", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1117  }
1118  }
1119  fixed (int* pLengths = lengths)
1120  {
1121  return InternalCreate((void*)runtimeType.TypeHandle.Value, lengths.Length, pLengths, null);
1122  }
1123  }
1124 
1139  public static Array CreateInstance(Type elementType, params long[] lengths)
1140  {
1141  if (lengths == null)
1142  {
1143  throw new ArgumentNullException("lengths");
1144  }
1145  if (lengths.Length == 0)
1146  {
1147  throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
1148  }
1149  int[] array = new int[lengths.Length];
1150  for (int i = 0; i < lengths.Length; i++)
1151  {
1152  long num = lengths[i];
1153  if (num > int.MaxValue || num < int.MinValue)
1154  {
1155  throw new ArgumentOutOfRangeException("len", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1156  }
1157  array[i] = (int)num;
1158  }
1159  return CreateInstance(elementType, array);
1160  }
1161 
1178  [SecuritySafeCritical]
1179  [__DynamicallyInvokable]
1180  public unsafe static Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
1181  {
1182  if (elementType == null)
1183  {
1184  throw new ArgumentNullException("elementType");
1185  }
1186  if (lengths == null)
1187  {
1188  throw new ArgumentNullException("lengths");
1189  }
1190  if (lowerBounds == null)
1191  {
1192  throw new ArgumentNullException("lowerBounds");
1193  }
1194  if (lengths.Length != lowerBounds.Length)
1195  {
1196  throw new ArgumentException(Environment.GetResourceString("Arg_RanksAndBounds"));
1197  }
1198  if (lengths.Length == 0)
1199  {
1200  throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank"));
1201  }
1202  RuntimeType runtimeType = elementType.UnderlyingSystemType as RuntimeType;
1203  if (runtimeType == null)
1204  {
1205  throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType");
1206  }
1207  for (int i = 0; i < lengths.Length; i++)
1208  {
1209  if (lengths[i] < 0)
1210  {
1211  throw new ArgumentOutOfRangeException("lengths[" + i + "]", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1212  }
1213  }
1214  fixed (int* pLengths = lengths)
1215  {
1216  fixed (int* pLowerBounds = lowerBounds)
1217  {
1218  return InternalCreate((void*)runtimeType.TypeHandle.Value, lengths.Length, pLengths, pLowerBounds);
1219  }
1220  }
1221  }
1222 
1223  [MethodImpl(MethodImplOptions.InternalCall)]
1224  [SecurityCritical]
1225  private unsafe static extern Array InternalCreate(void* elementType, int rank, int* pLengths, int* pLowerBounds);
1226 
1227  [SecurityCritical]
1228  [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
1229  internal static Array UnsafeCreateInstance(Type elementType, int length)
1230  {
1231  return CreateInstance(elementType, length);
1232  }
1233 
1234  [SecurityCritical]
1235  [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
1236  internal static Array UnsafeCreateInstance(Type elementType, int length1, int length2)
1237  {
1238  return CreateInstance(elementType, length1, length2);
1239  }
1240 
1241  [SecurityCritical]
1242  [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
1243  internal static Array UnsafeCreateInstance(Type elementType, params int[] lengths)
1244  {
1245  return CreateInstance(elementType, lengths);
1246  }
1247 
1248  [SecurityCritical]
1249  [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
1250  internal static Array UnsafeCreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
1251  {
1252  return CreateInstance(elementType, lengths, lowerBounds);
1253  }
1254 
1272  [SecuritySafeCritical]
1273  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
1274  [__DynamicallyInvokable]
1275  public static void Copy(Array sourceArray, Array destinationArray, int length)
1276  {
1277  if (sourceArray == null)
1278  {
1279  throw new ArgumentNullException("sourceArray");
1280  }
1281  if (destinationArray == null)
1282  {
1283  throw new ArgumentNullException("destinationArray");
1284  }
1285  Copy(sourceArray, sourceArray.GetLowerBound(0), destinationArray, destinationArray.GetLowerBound(0), length, reliable: false);
1286  }
1287 
1309  [SecuritySafeCritical]
1310  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
1311  [__DynamicallyInvokable]
1312  public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
1313  {
1314  Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable: false);
1315  }
1316 
1317  [MethodImpl(MethodImplOptions.InternalCall)]
1318  [SecurityCritical]
1319  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
1320  internal static extern void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable);
1321 
1342  [SecuritySafeCritical]
1343  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1344  [__DynamicallyInvokable]
1345  public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
1346  {
1347  Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable: true);
1348  }
1349 
1367  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
1368  public static void Copy(Array sourceArray, Array destinationArray, long length)
1369  {
1370  if (length > int.MaxValue || length < int.MinValue)
1371  {
1372  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1373  }
1374  Copy(sourceArray, destinationArray, (int)length);
1375  }
1376 
1398  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
1399  public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
1400  {
1401  if (sourceIndex > int.MaxValue || sourceIndex < int.MinValue)
1402  {
1403  throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1404  }
1405  if (destinationIndex > int.MaxValue || destinationIndex < int.MinValue)
1406  {
1407  throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1408  }
1409  if (length > int.MaxValue || length < int.MinValue)
1410  {
1411  throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1412  }
1413  Copy(sourceArray, (int)sourceIndex, destinationArray, (int)destinationIndex, (int)length);
1414  }
1415 
1425  [MethodImpl(MethodImplOptions.InternalCall)]
1426  [SecuritySafeCritical]
1427  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1428  [__DynamicallyInvokable]
1429  public static extern void Clear(Array array, int index, int length);
1430 
1438  [SecuritySafeCritical]
1439  [__DynamicallyInvokable]
1440  public unsafe object GetValue(params int[] indices)
1441  {
1442  if (indices == null)
1443  {
1444  throw new ArgumentNullException("indices");
1445  }
1446  if (Rank != indices.Length)
1447  {
1448  throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
1449  }
1450  TypedReference typedReference = default(TypedReference);
1451  fixed (int* pIndices = indices)
1452  {
1453  InternalGetReference(&typedReference, indices.Length, pIndices);
1454  }
1455  return TypedReference.InternalToObject(&typedReference);
1456  }
1457 
1464  [SecuritySafeCritical]
1465  [__DynamicallyInvokable]
1466  public unsafe object GetValue(int index)
1467  {
1468  if (Rank != 1)
1469  {
1470  throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray"));
1471  }
1472  TypedReference typedReference = default(TypedReference);
1473  InternalGetReference(&typedReference, 1, &index);
1474  return TypedReference.InternalToObject(&typedReference);
1475  }
1476 
1483  [SecuritySafeCritical]
1484  public unsafe object GetValue(int index1, int index2)
1485  {
1486  if (Rank != 2)
1487  {
1488  throw new ArgumentException(Environment.GetResourceString("Arg_Need2DArray"));
1489  }
1490  int* ptr = stackalloc int[2];
1491  *ptr = index1;
1492  ptr[1] = index2;
1493  TypedReference typedReference = default(TypedReference);
1494  InternalGetReference(&typedReference, 2, ptr);
1495  return TypedReference.InternalToObject(&typedReference);
1496  }
1497 
1506  [SecuritySafeCritical]
1507  public unsafe object GetValue(int index1, int index2, int index3)
1508  {
1509  if (Rank != 3)
1510  {
1511  throw new ArgumentException(Environment.GetResourceString("Arg_Need3DArray"));
1512  }
1513  int* ptr = stackalloc int[3];
1514  *ptr = index1;
1515  ptr[1] = index2;
1516  ptr[2] = index3;
1517  TypedReference typedReference = default(TypedReference);
1518  InternalGetReference(&typedReference, 3, ptr);
1519  return TypedReference.InternalToObject(&typedReference);
1520  }
1521 
1528  [ComVisible(false)]
1529  public object GetValue(long index)
1530  {
1531  if (index > int.MaxValue || index < int.MinValue)
1532  {
1533  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1534  }
1535  return GetValue((int)index);
1536  }
1537 
1544  [ComVisible(false)]
1545  public object GetValue(long index1, long index2)
1546  {
1547  if (index1 > int.MaxValue || index1 < int.MinValue)
1548  {
1549  throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1550  }
1551  if (index2 > int.MaxValue || index2 < int.MinValue)
1552  {
1553  throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1554  }
1555  return GetValue((int)index1, (int)index2);
1556  }
1557 
1566  [ComVisible(false)]
1567  public object GetValue(long index1, long index2, long index3)
1568  {
1569  if (index1 > int.MaxValue || index1 < int.MinValue)
1570  {
1571  throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1572  }
1573  if (index2 > int.MaxValue || index2 < int.MinValue)
1574  {
1575  throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1576  }
1577  if (index3 > int.MaxValue || index3 < int.MinValue)
1578  {
1579  throw new ArgumentOutOfRangeException("index3", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1580  }
1581  return GetValue((int)index1, (int)index2, (int)index3);
1582  }
1583 
1591  [ComVisible(false)]
1592  public object GetValue(params long[] indices)
1593  {
1594  if (indices == null)
1595  {
1596  throw new ArgumentNullException("indices");
1597  }
1598  if (Rank != indices.Length)
1599  {
1600  throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
1601  }
1602  int[] array = new int[indices.Length];
1603  for (int i = 0; i < indices.Length; i++)
1604  {
1605  long num = indices[i];
1606  if (num > int.MaxValue || num < int.MinValue)
1607  {
1608  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1609  }
1610  array[i] = (int)num;
1611  }
1612  return GetValue(array);
1613  }
1614 
1623  [SecuritySafeCritical]
1624  [__DynamicallyInvokable]
1625  public unsafe void SetValue(object value, int index)
1626  {
1627  if (Rank != 1)
1628  {
1629  throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray"));
1630  }
1631  TypedReference typedReference = default(TypedReference);
1632  InternalGetReference(&typedReference, 1, &index);
1633  InternalSetValue(&typedReference, value);
1634  }
1635 
1644  [SecuritySafeCritical]
1645  public unsafe void SetValue(object value, int index1, int index2)
1646  {
1647  if (Rank != 2)
1648  {
1649  throw new ArgumentException(Environment.GetResourceString("Arg_Need2DArray"));
1650  }
1651  int* ptr = stackalloc int[2];
1652  *ptr = index1;
1653  ptr[1] = index2;
1654  TypedReference typedReference = default(TypedReference);
1655  InternalGetReference(&typedReference, 2, ptr);
1656  InternalSetValue(&typedReference, value);
1657  }
1658 
1669  [SecuritySafeCritical]
1670  public unsafe void SetValue(object value, int index1, int index2, int index3)
1671  {
1672  if (Rank != 3)
1673  {
1674  throw new ArgumentException(Environment.GetResourceString("Arg_Need3DArray"));
1675  }
1676  int* ptr = stackalloc int[3];
1677  *ptr = index1;
1678  ptr[1] = index2;
1679  ptr[2] = index3;
1680  TypedReference typedReference = default(TypedReference);
1681  InternalGetReference(&typedReference, 3, ptr);
1682  InternalSetValue(&typedReference, value);
1683  }
1684 
1694  [SecuritySafeCritical]
1695  [__DynamicallyInvokable]
1696  public unsafe void SetValue(object value, params int[] indices)
1697  {
1698  if (indices == null)
1699  {
1700  throw new ArgumentNullException("indices");
1701  }
1702  if (Rank != indices.Length)
1703  {
1704  throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
1705  }
1706  TypedReference typedReference = default(TypedReference);
1707  fixed (int* pIndices = indices)
1708  {
1709  InternalGetReference(&typedReference, indices.Length, pIndices);
1710  }
1711  InternalSetValue(&typedReference, value);
1712  }
1713 
1722  [ComVisible(false)]
1723  public void SetValue(object value, long index)
1724  {
1725  if (index > int.MaxValue || index < int.MinValue)
1726  {
1727  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1728  }
1729  SetValue(value, (int)index);
1730  }
1731 
1740  [ComVisible(false)]
1741  public void SetValue(object value, long index1, long index2)
1742  {
1743  if (index1 > int.MaxValue || index1 < int.MinValue)
1744  {
1745  throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1746  }
1747  if (index2 > int.MaxValue || index2 < int.MinValue)
1748  {
1749  throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1750  }
1751  SetValue(value, (int)index1, (int)index2);
1752  }
1753 
1764  [ComVisible(false)]
1765  public void SetValue(object value, long index1, long index2, long index3)
1766  {
1767  if (index1 > int.MaxValue || index1 < int.MinValue)
1768  {
1769  throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1770  }
1771  if (index2 > int.MaxValue || index2 < int.MinValue)
1772  {
1773  throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1774  }
1775  if (index3 > int.MaxValue || index3 < int.MinValue)
1776  {
1777  throw new ArgumentOutOfRangeException("index3", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1778  }
1779  SetValue(value, (int)index1, (int)index2, (int)index3);
1780  }
1781 
1791  [ComVisible(false)]
1792  public void SetValue(object value, params long[] indices)
1793  {
1794  if (indices == null)
1795  {
1796  throw new ArgumentNullException("indices");
1797  }
1798  if (Rank != indices.Length)
1799  {
1800  throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices"));
1801  }
1802  int[] array = new int[indices.Length];
1803  for (int i = 0; i < indices.Length; i++)
1804  {
1805  long num = indices[i];
1806  if (num > int.MaxValue || num < int.MinValue)
1807  {
1808  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
1809  }
1810  array[i] = (int)num;
1811  }
1812  SetValue(value, array);
1813  }
1814 
1815  [MethodImpl(MethodImplOptions.InternalCall)]
1816  [SecurityCritical]
1817  private unsafe extern void InternalGetReference(void* elemRef, int rank, int* pIndices);
1818 
1819  [MethodImpl(MethodImplOptions.InternalCall)]
1820  [SecurityCritical]
1821  private unsafe static extern void InternalSetValue(void* target, object value);
1822 
1823  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1824  private static int GetMedian(int low, int hi)
1825  {
1826  return low + (hi - low >> 1);
1827  }
1828 
1835  [MethodImpl(MethodImplOptions.InternalCall)]
1836  [SecuritySafeCritical]
1837  [__DynamicallyInvokable]
1838  public extern int GetLength(int dimension);
1839 
1846  [ComVisible(false)]
1847  public long GetLongLength(int dimension)
1848  {
1849  return GetLength(dimension);
1850  }
1851 
1858  [MethodImpl(MethodImplOptions.InternalCall)]
1859  [SecuritySafeCritical]
1860  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1861  [__DynamicallyInvokable]
1862  public extern int GetUpperBound(int dimension);
1863 
1870  [MethodImpl(MethodImplOptions.InternalCall)]
1871  [SecuritySafeCritical]
1872  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1873  [__DynamicallyInvokable]
1874  public extern int GetLowerBound(int dimension);
1875 
1876  [MethodImpl(MethodImplOptions.InternalCall)]
1877  [SecurityCritical]
1878  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1879  internal extern int GetDataPtrOffsetInternal();
1880 
1885  [__DynamicallyInvokable]
1886  int IList.Add(object value)
1887  {
1888  throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
1889  }
1890 
1895  [__DynamicallyInvokable]
1896  bool IList.Contains(object value)
1897  {
1898  return IndexOf(this, value) >= GetLowerBound(0);
1899  }
1900 
1903  [__DynamicallyInvokable]
1904  void IList.Clear()
1905  {
1906  Clear(this, GetLowerBound(0), Length);
1907  }
1908 
1912  [__DynamicallyInvokable]
1913  int IList.IndexOf(object value)
1914  {
1915  return IndexOf(this, value);
1916  }
1917 
1926  [__DynamicallyInvokable]
1927  void IList.Insert(int index, object value)
1928  {
1929  throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
1930  }
1931 
1935  [__DynamicallyInvokable]
1936  void IList.Remove(object value)
1937  {
1938  throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
1939  }
1940 
1945  [__DynamicallyInvokable]
1946  void IList.RemoveAt(int index)
1947  {
1948  throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection"));
1949  }
1950 
1953  [__DynamicallyInvokable]
1954  public object Clone()
1955  {
1956  return MemberwiseClone();
1957  }
1958 
1963  [__DynamicallyInvokable]
1964  int IStructuralComparable.CompareTo(object other, IComparer comparer)
1965  {
1966  if (other == null)
1967  {
1968  return 1;
1969  }
1970  Array array = other as Array;
1971  if (array == null || Length != array.Length)
1972  {
1973  throw new ArgumentException(Environment.GetResourceString("ArgumentException_OtherNotArrayOfCorrectLength"), "other");
1974  }
1975  int i = 0;
1976  int num = 0;
1977  for (; i < array.Length; i++)
1978  {
1979  if (num != 0)
1980  {
1981  break;
1982  }
1983  object value = GetValue(i);
1984  object value2 = array.GetValue(i);
1985  num = comparer.Compare(value, value2);
1986  }
1987  return num;
1988  }
1989 
1995  [__DynamicallyInvokable]
1996  bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
1997  {
1998  if (other == null)
1999  {
2000  return false;
2001  }
2002  if (this == other)
2003  {
2004  return true;
2005  }
2006  Array array = other as Array;
2007  if (array == null || array.Length != Length)
2008  {
2009  return false;
2010  }
2011  for (int i = 0; i < array.Length; i++)
2012  {
2013  object value = GetValue(i);
2014  object value2 = array.GetValue(i);
2015  if (!comparer.Equals(value, value2))
2016  {
2017  return false;
2018  }
2019  }
2020  return true;
2021  }
2022 
2023  internal static int CombineHashCodes(int h1, int h2)
2024  {
2025  return ((h1 << 5) + h1) ^ h2;
2026  }
2027 
2031  [__DynamicallyInvokable]
2033  {
2034  if (comparer == null)
2035  {
2036  throw new ArgumentNullException("comparer");
2037  }
2038  int num = 0;
2039  for (int i = (Length >= 8) ? (Length - 8) : 0; i < Length; i++)
2040  {
2041  num = CombineHashCodes(num, comparer.GetHashCode(GetValue(i)));
2042  }
2043  return num;
2044  }
2045 
2058  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2059  [__DynamicallyInvokable]
2060  public static int BinarySearch(Array array, object value)
2061  {
2062  if (array == null)
2063  {
2064  throw new ArgumentNullException("array");
2065  }
2066  int lowerBound = array.GetLowerBound(0);
2067  return BinarySearch(array, lowerBound, array.Length, value, null);
2068  }
2069 
2088  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2089  [__DynamicallyInvokable]
2090  public static int BinarySearch(Array array, int index, int length, object value)
2091  {
2092  return BinarySearch(array, index, length, value, null);
2093  }
2094 
2109  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2110  [__DynamicallyInvokable]
2111  public static int BinarySearch(Array array, object value, IComparer comparer)
2112  {
2113  if (array == null)
2114  {
2115  throw new ArgumentNullException("array");
2116  }
2117  int lowerBound = array.GetLowerBound(0);
2118  return BinarySearch(array, lowerBound, array.Length, value, comparer);
2119  }
2120 
2141  [SecuritySafeCritical]
2142  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2143  [__DynamicallyInvokable]
2144  public static int BinarySearch(Array array, int index, int length, object value, IComparer comparer)
2145  {
2146  if (array == null)
2147  {
2148  throw new ArgumentNullException("array");
2149  }
2150  int lowerBound = array.GetLowerBound(0);
2151  if (index < lowerBound || length < 0)
2152  {
2153  throw new ArgumentOutOfRangeException((index < lowerBound) ? "index" : "length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
2154  }
2155  if (array.Length - (index - lowerBound) < length)
2156  {
2157  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
2158  }
2159  if (array.Rank != 1)
2160  {
2161  throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
2162  }
2163  if (comparer == null)
2164  {
2165  comparer = Comparer.Default;
2166  }
2167  if (comparer == Comparer.Default && TrySZBinarySearch(array, index, length, value, out int retVal))
2168  {
2169  return retVal;
2170  }
2171  int num = index;
2172  int num2 = index + length - 1;
2173  object[] array2 = array as object[];
2174  if (array2 != null)
2175  {
2176  while (num <= num2)
2177  {
2178  int median = GetMedian(num, num2);
2179  int num3;
2180  try
2181  {
2182  num3 = comparer.Compare(array2[median], value);
2183  }
2184  catch (Exception innerException)
2185  {
2186  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
2187  }
2188  if (num3 == 0)
2189  {
2190  return median;
2191  }
2192  if (num3 < 0)
2193  {
2194  num = median + 1;
2195  }
2196  else
2197  {
2198  num2 = median - 1;
2199  }
2200  }
2201  }
2202  else
2203  {
2204  while (num <= num2)
2205  {
2206  int median2 = GetMedian(num, num2);
2207  int num4;
2208  try
2209  {
2210  num4 = comparer.Compare(array.GetValue(median2), value);
2211  }
2212  catch (Exception innerException2)
2213  {
2214  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException2);
2215  }
2216  if (num4 == 0)
2217  {
2218  return median2;
2219  }
2220  if (num4 < 0)
2221  {
2222  num = median2 + 1;
2223  }
2224  else
2225  {
2226  num2 = median2 - 1;
2227  }
2228  }
2229  }
2230  return ~num;
2231  }
2232 
2233  [MethodImpl(MethodImplOptions.InternalCall)]
2234  [SecurityCritical]
2235  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2236  private static extern bool TrySZBinarySearch(Array sourceArray, int sourceIndex, int count, object value, out int retVal);
2237 
2247  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2248  [__DynamicallyInvokable]
2249  public static int BinarySearch<T>(T[] array, T value)
2250  {
2251  if (array == null)
2252  {
2253  throw new ArgumentNullException("array");
2254  }
2255  return BinarySearch(array, 0, array.Length, value, null);
2256  }
2257 
2271  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2272  [__DynamicallyInvokable]
2273  public static int BinarySearch<T>(T[] array, T value, IComparer<T> comparer)
2274  {
2275  if (array == null)
2276  {
2277  throw new ArgumentNullException("array");
2278  }
2279  return BinarySearch(array, 0, array.Length, value, comparer);
2280  }
2281 
2299  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2300  [__DynamicallyInvokable]
2301  public static int BinarySearch<T>(T[] array, int index, int length, T value)
2302  {
2303  return BinarySearch(array, index, length, value, null);
2304  }
2305 
2325  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2326  [__DynamicallyInvokable]
2327  public static int BinarySearch<T>(T[] array, int index, int length, T value, IComparer<T> comparer)
2328  {
2329  if (array == null)
2330  {
2331  throw new ArgumentNullException("array");
2332  }
2333  if (index < 0 || length < 0)
2334  {
2335  throw new ArgumentOutOfRangeException((index < 0) ? "index" : "length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
2336  }
2337  if (array.Length - index < length)
2338  {
2339  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
2340  }
2341  return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer);
2342  }
2343 
2353  public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] array, Converter<TInput, TOutput> converter)
2354  {
2355  if (array == null)
2356  {
2357  throw new ArgumentNullException("array");
2358  }
2359  if (converter == null)
2360  {
2361  throw new ArgumentNullException("converter");
2362  }
2363  TOutput[] array2 = new TOutput[array.Length];
2364  for (int i = 0; i < array.Length; i++)
2365  {
2366  array2[i] = converter(array[i]);
2367  }
2368  return array2;
2369  }
2370 
2383  [__DynamicallyInvokable]
2384  public void CopyTo(Array array, int index)
2385  {
2386  if (array != null && array.Rank != 1)
2387  {
2388  throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
2389  }
2390  Copy(this, GetLowerBound(0), array, index, Length);
2391  }
2392 
2405  [ComVisible(false)]
2406  public void CopyTo(Array array, long index)
2407  {
2408  if (index > int.MaxValue || index < int.MinValue)
2409  {
2410  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported"));
2411  }
2412  CopyTo(array, (int)index);
2413  }
2414 
2418  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2419  [__DynamicallyInvokable]
2420  public static T[] Empty<T>()
2421  {
2422  return EmptyArray<T>.Value;
2423  }
2424 
2434  [__DynamicallyInvokable]
2435  public static bool Exists<T>(T[] array, Predicate<T> match)
2436  {
2437  return FindIndex(array, match) != -1;
2438  }
2439 
2448  [__DynamicallyInvokable]
2449  public static T Find<T>(T[] array, Predicate<T> match)
2450  {
2451  if (array == null)
2452  {
2453  throw new ArgumentNullException("array");
2454  }
2455  if (match == null)
2456  {
2457  throw new ArgumentNullException("match");
2458  }
2459  for (int i = 0; i < array.Length; i++)
2460  {
2461  if (match(array[i]))
2462  {
2463  return array[i];
2464  }
2465  }
2466  return default(T);
2467  }
2468 
2477  [__DynamicallyInvokable]
2478  public static T[] FindAll<T>(T[] array, Predicate<T> match)
2479  {
2480  if (array == null)
2481  {
2482  throw new ArgumentNullException("array");
2483  }
2484  if (match == null)
2485  {
2486  throw new ArgumentNullException("match");
2487  }
2488  List<T> list = new List<T>();
2489  for (int i = 0; i < array.Length; i++)
2490  {
2491  if (match(array[i]))
2492  {
2493  list.Add(array[i]);
2494  }
2495  }
2496  return list.ToArray();
2497  }
2498 
2507  [__DynamicallyInvokable]
2508  public static int FindIndex<T>(T[] array, Predicate<T> match)
2509  {
2510  if (array == null)
2511  {
2512  throw new ArgumentNullException("array");
2513  }
2514  return FindIndex(array, 0, array.Length, match);
2515  }
2516 
2528  [__DynamicallyInvokable]
2529  public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match)
2530  {
2531  if (array == null)
2532  {
2533  throw new ArgumentNullException("array");
2534  }
2535  return FindIndex(array, startIndex, array.Length - startIndex, match);
2536  }
2537 
2552  [__DynamicallyInvokable]
2553  public static int FindIndex<T>(T[] array, int startIndex, int count, Predicate<T> match)
2554  {
2555  if (array == null)
2556  {
2557  throw new ArgumentNullException("array");
2558  }
2559  if (startIndex < 0 || startIndex > array.Length)
2560  {
2561  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2562  }
2563  if (count < 0 || startIndex > array.Length - count)
2564  {
2565  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2566  }
2567  if (match == null)
2568  {
2569  throw new ArgumentNullException("match");
2570  }
2571  int num = startIndex + count;
2572  for (int i = startIndex; i < num; i++)
2573  {
2574  if (match(array[i]))
2575  {
2576  return i;
2577  }
2578  }
2579  return -1;
2580  }
2581 
2590  [__DynamicallyInvokable]
2591  public static T FindLast<T>(T[] array, Predicate<T> match)
2592  {
2593  if (array == null)
2594  {
2595  throw new ArgumentNullException("array");
2596  }
2597  if (match == null)
2598  {
2599  throw new ArgumentNullException("match");
2600  }
2601  for (int num = array.Length - 1; num >= 0; num--)
2602  {
2603  if (match(array[num]))
2604  {
2605  return array[num];
2606  }
2607  }
2608  return default(T);
2609  }
2610 
2619  [__DynamicallyInvokable]
2620  public static int FindLastIndex<T>(T[] array, Predicate<T> match)
2621  {
2622  if (array == null)
2623  {
2624  throw new ArgumentNullException("array");
2625  }
2626  return FindLastIndex(array, array.Length - 1, array.Length, match);
2627  }
2628 
2640  [__DynamicallyInvokable]
2641  public static int FindLastIndex<T>(T[] array, int startIndex, Predicate<T> match)
2642  {
2643  if (array == null)
2644  {
2645  throw new ArgumentNullException("array");
2646  }
2647  return FindLastIndex(array, startIndex, startIndex + 1, match);
2648  }
2649 
2664  [__DynamicallyInvokable]
2665  public static int FindLastIndex<T>(T[] array, int startIndex, int count, Predicate<T> match)
2666  {
2667  if (array == null)
2668  {
2669  throw new ArgumentNullException("array");
2670  }
2671  if (match == null)
2672  {
2673  throw new ArgumentNullException("match");
2674  }
2675  if (array.Length == 0)
2676  {
2677  if (startIndex != -1)
2678  {
2679  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2680  }
2681  }
2682  else if (startIndex < 0 || startIndex >= array.Length)
2683  {
2684  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2685  }
2686  if (count < 0 || startIndex - count + 1 < 0)
2687  {
2688  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2689  }
2690  int num = startIndex - count;
2691  for (int num2 = startIndex; num2 > num; num2--)
2692  {
2693  if (match(array[num2]))
2694  {
2695  return num2;
2696  }
2697  }
2698  return -1;
2699  }
2700 
2708  public static void ForEach<T>(T[] array, Action<T> action)
2709  {
2710  if (array == null)
2711  {
2712  throw new ArgumentNullException("array");
2713  }
2714  if (action == null)
2715  {
2716  throw new ArgumentNullException("action");
2717  }
2718  for (int i = 0; i < array.Length; i++)
2719  {
2720  action(array[i]);
2721  }
2722  }
2723 
2726  [__DynamicallyInvokable]
2728  {
2729  int lowerBound = GetLowerBound(0);
2730  if (Rank == 1 && lowerBound == 0)
2731  {
2732  return new SZArrayEnumerator(this);
2733  }
2734  return new ArrayEnumerator(this, lowerBound, Length);
2735  }
2736 
2745  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2746  [__DynamicallyInvokable]
2747  public static int IndexOf(Array array, object value)
2748  {
2749  if (array == null)
2750  {
2751  throw new ArgumentNullException("array");
2752  }
2753  int lowerBound = array.GetLowerBound(0);
2754  return IndexOf(array, value, lowerBound, array.Length);
2755  }
2756 
2768  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2769  [__DynamicallyInvokable]
2770  public static int IndexOf(Array array, object value, int startIndex)
2771  {
2772  if (array == null)
2773  {
2774  throw new ArgumentNullException("array");
2775  }
2776  int lowerBound = array.GetLowerBound(0);
2777  return IndexOf(array, value, startIndex, array.Length - startIndex + lowerBound);
2778  }
2779 
2794  [SecuritySafeCritical]
2795  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2796  [__DynamicallyInvokable]
2797  public static int IndexOf(Array array, object value, int startIndex, int count)
2798  {
2799  if (array == null)
2800  {
2801  throw new ArgumentNullException("array");
2802  }
2803  if (array.Rank != 1)
2804  {
2805  throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
2806  }
2807  int lowerBound = array.GetLowerBound(0);
2808  if (startIndex < lowerBound || startIndex > array.Length + lowerBound)
2809  {
2810  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2811  }
2812  if (count < 0 || count > array.Length - startIndex + lowerBound)
2813  {
2814  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2815  }
2816  if (TrySZIndexOf(array, startIndex, count, value, out int retVal))
2817  {
2818  return retVal;
2819  }
2820  object[] array2 = array as object[];
2821  int num = startIndex + count;
2822  if (array2 != null)
2823  {
2824  if (value == null)
2825  {
2826  for (int i = startIndex; i < num; i++)
2827  {
2828  if (array2[i] == null)
2829  {
2830  return i;
2831  }
2832  }
2833  }
2834  else
2835  {
2836  for (int j = startIndex; j < num; j++)
2837  {
2838  object obj = array2[j];
2839  if (obj != null && obj.Equals(value))
2840  {
2841  return j;
2842  }
2843  }
2844  }
2845  }
2846  else
2847  {
2848  for (int k = startIndex; k < num; k++)
2849  {
2850  object value2 = array.GetValue(k);
2851  if (value2 == null)
2852  {
2853  if (value == null)
2854  {
2855  return k;
2856  }
2857  }
2858  else if (value2.Equals(value))
2859  {
2860  return k;
2861  }
2862  }
2863  }
2864  return lowerBound - 1;
2865  }
2866 
2874  [__DynamicallyInvokable]
2875  public static int IndexOf<T>(T[] array, T value)
2876  {
2877  if (array == null)
2878  {
2879  throw new ArgumentNullException("array");
2880  }
2881  return IndexOf(array, value, 0, array.Length);
2882  }
2883 
2894  [__DynamicallyInvokable]
2895  public static int IndexOf<T>(T[] array, T value, int startIndex)
2896  {
2897  if (array == null)
2898  {
2899  throw new ArgumentNullException("array");
2900  }
2901  return IndexOf(array, value, startIndex, array.Length - startIndex);
2902  }
2903 
2917  [__DynamicallyInvokable]
2918  public static int IndexOf<T>(T[] array, T value, int startIndex, int count)
2919  {
2920  if (array == null)
2921  {
2922  throw new ArgumentNullException("array");
2923  }
2924  if (startIndex < 0 || startIndex > array.Length)
2925  {
2926  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
2927  }
2928  if (count < 0 || count > array.Length - startIndex)
2929  {
2930  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
2931  }
2932  return EqualityComparer<T>.Default.IndexOf(array, value, startIndex, count);
2933  }
2934 
2935  [MethodImpl(MethodImplOptions.InternalCall)]
2936  [SecurityCritical]
2937  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2938  private static extern bool TrySZIndexOf(Array sourceArray, int sourceIndex, int count, object value, out int retVal);
2939 
2948  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2949  [__DynamicallyInvokable]
2950  public static int LastIndexOf(Array array, object value)
2951  {
2952  if (array == null)
2953  {
2954  throw new ArgumentNullException("array");
2955  }
2956  int lowerBound = array.GetLowerBound(0);
2957  return LastIndexOf(array, value, array.Length - 1 + lowerBound, array.Length);
2958  }
2959 
2971  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2972  [__DynamicallyInvokable]
2973  public static int LastIndexOf(Array array, object value, int startIndex)
2974  {
2975  if (array == null)
2976  {
2977  throw new ArgumentNullException("array");
2978  }
2979  int lowerBound = array.GetLowerBound(0);
2980  return LastIndexOf(array, value, startIndex, startIndex + 1 - lowerBound);
2981  }
2982 
2997  [SecuritySafeCritical]
2998  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
2999  [__DynamicallyInvokable]
3000  public static int LastIndexOf(Array array, object value, int startIndex, int count)
3001  {
3002  if (array == null)
3003  {
3004  throw new ArgumentNullException("array");
3005  }
3006  int lowerBound = array.GetLowerBound(0);
3007  if (array.Length == 0)
3008  {
3009  return lowerBound - 1;
3010  }
3011  if (startIndex < lowerBound || startIndex >= array.Length + lowerBound)
3012  {
3013  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
3014  }
3015  if (count < 0)
3016  {
3017  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
3018  }
3019  if (count > startIndex - lowerBound + 1)
3020  {
3021  throw new ArgumentOutOfRangeException("endIndex", Environment.GetResourceString("ArgumentOutOfRange_EndIndexStartIndex"));
3022  }
3023  if (array.Rank != 1)
3024  {
3025  throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
3026  }
3027  if (TrySZLastIndexOf(array, startIndex, count, value, out int retVal))
3028  {
3029  return retVal;
3030  }
3031  object[] array2 = array as object[];
3032  int num = startIndex - count + 1;
3033  if (array2 != null)
3034  {
3035  if (value == null)
3036  {
3037  for (int num2 = startIndex; num2 >= num; num2--)
3038  {
3039  if (array2[num2] == null)
3040  {
3041  return num2;
3042  }
3043  }
3044  }
3045  else
3046  {
3047  for (int num3 = startIndex; num3 >= num; num3--)
3048  {
3049  object obj = array2[num3];
3050  if (obj != null && obj.Equals(value))
3051  {
3052  return num3;
3053  }
3054  }
3055  }
3056  }
3057  else
3058  {
3059  for (int num4 = startIndex; num4 >= num; num4--)
3060  {
3061  object value2 = array.GetValue(num4);
3062  if (value2 == null)
3063  {
3064  if (value == null)
3065  {
3066  return num4;
3067  }
3068  }
3069  else if (value2.Equals(value))
3070  {
3071  return num4;
3072  }
3073  }
3074  }
3075  return lowerBound - 1;
3076  }
3077 
3085  [__DynamicallyInvokable]
3086  public static int LastIndexOf<T>(T[] array, T value)
3087  {
3088  if (array == null)
3089  {
3090  throw new ArgumentNullException("array");
3091  }
3092  return LastIndexOf(array, value, array.Length - 1, array.Length);
3093  }
3094 
3105  [__DynamicallyInvokable]
3106  public static int LastIndexOf<T>(T[] array, T value, int startIndex)
3107  {
3108  if (array == null)
3109  {
3110  throw new ArgumentNullException("array");
3111  }
3112  return LastIndexOf(array, value, startIndex, (array.Length != 0) ? (startIndex + 1) : 0);
3113  }
3114 
3128  [__DynamicallyInvokable]
3129  public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count)
3130  {
3131  if (array == null)
3132  {
3133  throw new ArgumentNullException("array");
3134  }
3135  if (array.Length == 0)
3136  {
3137  if (startIndex != -1 && startIndex != 0)
3138  {
3139  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
3140  }
3141  if (count != 0)
3142  {
3143  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
3144  }
3145  return -1;
3146  }
3147  if (startIndex < 0 || startIndex >= array.Length)
3148  {
3149  throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
3150  }
3151  if (count < 0 || startIndex - count + 1 < 0)
3152  {
3153  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
3154  }
3155  return EqualityComparer<T>.Default.LastIndexOf(array, value, startIndex, count);
3156  }
3157 
3158  [MethodImpl(MethodImplOptions.InternalCall)]
3159  [SecurityCritical]
3160  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
3161  private static extern bool TrySZLastIndexOf(Array sourceArray, int sourceIndex, int count, object value, out int retVal);
3162 
3169  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3170  [__DynamicallyInvokable]
3171  public static void Reverse(Array array)
3172  {
3173  if (array == null)
3174  {
3175  throw new ArgumentNullException("array");
3176  }
3177  Reverse(array, array.GetLowerBound(0), array.Length);
3178  }
3179 
3193  [SecuritySafeCritical]
3194  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3195  [__DynamicallyInvokable]
3196  public static void Reverse(Array array, int index, int length)
3197  {
3198  if (array == null)
3199  {
3200  throw new ArgumentNullException("array");
3201  }
3202  if (index < array.GetLowerBound(0) || length < 0)
3203  {
3204  throw new ArgumentOutOfRangeException((index < 0) ? "index" : "length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
3205  }
3206  if (array.Length - (index - array.GetLowerBound(0)) < length)
3207  {
3208  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
3209  }
3210  if (array.Rank != 1)
3211  {
3212  throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
3213  }
3214  if (TrySZReverse(array, index, length))
3215  {
3216  return;
3217  }
3218  int num = index;
3219  int num2 = index + length - 1;
3220  object[] array2 = array as object[];
3221  if (array2 != null)
3222  {
3223  while (num < num2)
3224  {
3225  object obj = array2[num];
3226  array2[num] = array2[num2];
3227  array2[num2] = obj;
3228  num++;
3229  num2--;
3230  }
3231  }
3232  else
3233  {
3234  while (num < num2)
3235  {
3236  object value = array.GetValue(num);
3237  array.SetValue(array.GetValue(num2), num);
3238  array.SetValue(value, num2);
3239  num++;
3240  num2--;
3241  }
3242  }
3243  }
3244 
3245  [MethodImpl(MethodImplOptions.InternalCall)]
3246  [SecurityCritical]
3247  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3248  private static extern bool TrySZReverse(Array array, int index, int count);
3249 
3257  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3258  [__DynamicallyInvokable]
3259  public static void Sort(Array array)
3260  {
3261  if (array == null)
3262  {
3263  throw new ArgumentNullException("array");
3264  }
3265  Sort(array, null, array.GetLowerBound(0), array.Length, null);
3266  }
3267 
3278  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3279  [__DynamicallyInvokable]
3280  public static void Sort(Array keys, Array items)
3281  {
3282  if (keys == null)
3283  {
3284  throw new ArgumentNullException("keys");
3285  }
3286  Sort(keys, items, keys.GetLowerBound(0), keys.Length, null);
3287  }
3288 
3303  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3304  [__DynamicallyInvokable]
3305  public static void Sort(Array array, int index, int length)
3306  {
3307  Sort(array, null, index, length, null);
3308  }
3309 
3327  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3328  [__DynamicallyInvokable]
3329  public static void Sort(Array keys, Array items, int index, int length)
3330  {
3331  Sort(keys, items, index, length, null);
3332  }
3333 
3345  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3346  [__DynamicallyInvokable]
3347  public static void Sort(Array array, IComparer comparer)
3348  {
3349  if (array == null)
3350  {
3351  throw new ArgumentNullException("array");
3352  }
3353  Sort(array, null, array.GetLowerBound(0), array.Length, comparer);
3354  }
3355 
3370  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3371  [__DynamicallyInvokable]
3372  public static void Sort(Array keys, Array items, IComparer comparer)
3373  {
3374  if (keys == null)
3375  {
3376  throw new ArgumentNullException("keys");
3377  }
3378  Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer);
3379  }
3380 
3399  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3400  [__DynamicallyInvokable]
3401  public static void Sort(Array array, int index, int length, IComparer comparer)
3402  {
3403  Sort(array, null, index, length, comparer);
3404  }
3405 
3428  [SecuritySafeCritical]
3429  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3430  [__DynamicallyInvokable]
3431  public static void Sort(Array keys, Array items, int index, int length, IComparer comparer)
3432  {
3433  if (keys == null)
3434  {
3435  throw new ArgumentNullException("keys");
3436  }
3437  if (keys.Rank != 1 || (items != null && items.Rank != 1))
3438  {
3439  throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
3440  }
3441  if (items != null && keys.GetLowerBound(0) != items.GetLowerBound(0))
3442  {
3443  throw new ArgumentException(Environment.GetResourceString("Arg_LowerBoundsMustMatch"));
3444  }
3445  if (index < keys.GetLowerBound(0) || length < 0)
3446  {
3447  throw new ArgumentOutOfRangeException((length < 0) ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
3448  }
3449  if (keys.Length - (index - keys.GetLowerBound(0)) < length || (items != null && index - items.GetLowerBound(0) > items.Length - length))
3450  {
3451  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
3452  }
3453  if (length > 1 && ((comparer != Comparer.Default && comparer != null) || !TrySZSort(keys, items, index, index + length - 1)))
3454  {
3455  object[] array = keys as object[];
3456  object[] array2 = null;
3457  if (array != null)
3458  {
3459  array2 = (items as object[]);
3460  }
3461  if (array != null && (items == null || array2 != null))
3462  {
3463  new SorterObjectArray(array, array2, comparer).Sort(index, length);
3464  }
3465  else
3466  {
3467  new SorterGenericArray(keys, items, comparer).Sort(index, length);
3468  }
3469  }
3470  }
3471 
3472  [MethodImpl(MethodImplOptions.InternalCall)]
3473  [SecurityCritical]
3474  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3475  private static extern bool TrySZSort(Array keys, Array items, int left, int right);
3476 
3483  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3484  [__DynamicallyInvokable]
3485  public static void Sort<T>(T[] array)
3486  {
3487  if (array == null)
3488  {
3489  throw new ArgumentNullException("array");
3490  }
3491  Sort(array, array.GetLowerBound(0), array.Length, null);
3492  }
3493 
3505  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3506  [__DynamicallyInvokable]
3507  public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items)
3508  {
3509  if (keys == null)
3510  {
3511  throw new ArgumentNullException("keys");
3512  }
3513  Sort(keys, items, 0, keys.Length, null);
3514  }
3515 
3529  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3530  [__DynamicallyInvokable]
3531  public static void Sort<T>(T[] array, int index, int length)
3532  {
3533  Sort(array, index, length, null);
3534  }
3535 
3554  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3555  [__DynamicallyInvokable]
3556  public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length)
3557  {
3558  Sort(keys, items, index, length, null);
3559  }
3560 
3570  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3571  [__DynamicallyInvokable]
3572  public static void Sort<T>(T[] array, IComparer<T> comparer)
3573  {
3574  if (array == null)
3575  {
3576  throw new ArgumentNullException("array");
3577  }
3578  Sort(array, 0, array.Length, comparer);
3579  }
3580 
3595  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3596  [__DynamicallyInvokable]
3597  public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, IComparer<TKey> comparer)
3598  {
3599  if (keys == null)
3600  {
3601  throw new ArgumentNullException("keys");
3602  }
3603  Sort(keys, items, 0, keys.Length, comparer);
3604  }
3605 
3622  [SecuritySafeCritical]
3623  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3624  [__DynamicallyInvokable]
3625  public static void Sort<T>(T[] array, int index, int length, IComparer<T> comparer)
3626  {
3627  if (array == null)
3628  {
3629  throw new ArgumentNullException("array");
3630  }
3631  if (index < 0 || length < 0)
3632  {
3633  throw new ArgumentOutOfRangeException((length < 0) ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
3634  }
3635  if (array.Length - index < length)
3636  {
3637  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
3638  }
3639  if (length > 1 && ((comparer != null && comparer != Comparer<T>.Default) || !TrySZSort(array, null, index, index + length - 1)))
3640  {
3641  ArraySortHelper<T>.Default.Sort(array, index, length, comparer);
3642  }
3643  }
3644 
3666  [SecuritySafeCritical]
3667  [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
3668  [__DynamicallyInvokable]
3669  public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length, IComparer<TKey> comparer)
3670  {
3671  if (keys == null)
3672  {
3673  throw new ArgumentNullException("keys");
3674  }
3675  if (index < 0 || length < 0)
3676  {
3677  throw new ArgumentOutOfRangeException((length < 0) ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
3678  }
3679  if (keys.Length - index < length || (items != null && index > items.Length - length))
3680  {
3681  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
3682  }
3683  if (length > 1 && ((comparer != null && comparer != Comparer<TKey>.Default) || !TrySZSort(keys, items, index, index + length - 1)))
3684  {
3685  if (items == null)
3686  {
3687  Sort(keys, index, length, comparer);
3688  }
3689  else
3690  {
3691  ArraySortHelper<TKey, TValue>.Default.Sort(keys, items, index, length, comparer);
3692  }
3693  }
3694  }
3695 
3704  [__DynamicallyInvokable]
3705  public static void Sort<T>(T[] array, Comparison<T> comparison)
3706  {
3707  if (array == null)
3708  {
3709  throw new ArgumentNullException("array");
3710  }
3711  if (comparison == null)
3712  {
3713  throw new ArgumentNullException("comparison");
3714  }
3715  IComparer<T> comparer = new FunctorComparer<T>(comparison);
3716  Sort(array, comparer);
3717  }
3718 
3728  [__DynamicallyInvokable]
3729  public static bool TrueForAll<T>(T[] array, Predicate<T> match)
3730  {
3731  if (array == null)
3732  {
3733  throw new ArgumentNullException("array");
3734  }
3735  if (match == null)
3736  {
3737  throw new ArgumentNullException("match");
3738  }
3739  for (int i = 0; i < array.Length; i++)
3740  {
3741  if (!match(array[i]))
3742  {
3743  return false;
3744  }
3745  }
3746  return true;
3747  }
3748 
3750  [MethodImpl(MethodImplOptions.InternalCall)]
3751  [SecuritySafeCritical]
3752  [__DynamicallyInvokable]
3753  public extern void Initialize();
3754  }
3755 }
static int LastIndexOf(Array array, object value, int startIndex)
Searches for the specified object and returns the index of the last occurrence within the range of el...
Definition: Array.cs:2973
bool Equals(object other, IEqualityComparer comparer)
Determines whether an object is structurally equal to the current instance.
static bool TrueForAll< T >(T[] array, Predicate< T > match)
Determines whether every element in the array matches the conditions defined by the specified predica...
Definition: Array.cs:3729
Compares two objects for equivalence, where string comparisons are case-sensitive.
Definition: Comparer.cs:11
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
unsafe void SetValue(object value, int index1, int index2, int index3)
Sets a value to the element at the specified position in the three-dimensional T:System....
Definition: Array.cs:1670
bool IsReadOnly
Gets a value indicating whether the T:System.Array is read-only.
Definition: Array.cs:878
static void Reverse(Array array, int index, int length)
Reverses the sequence of the elements in a range of elements in the one-dimensional T:System....
Definition: Array.cs:3196
static void Resize< T >(ref T[] array, int newSize)
Changes the number of elements of a one-dimensional array to the specified new size.
Definition: Array.cs:937
Provides the base class for a generic read-only collection.
static T Find< T >(T[] array, Predicate< T > match)
Searches for an element that matches the conditions defined by the specified predicate,...
Definition: Array.cs:2449
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.
static void Sort(Array array, int index, int length)
Sorts the elements in a range of elements in a one-dimensional T:System.Array using the T:System....
Definition: Array.cs:3305
static void Copy(Array sourceArray, Array destinationArray, long length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1368
static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length)
Copies a range of elements from an T:System.Array starting at the specified source index and pastes t...
Definition: Array.cs:1399
void CopyTo(Array array, int index)
Copies all the elements of the current one-dimensional array to the specified one-dimensional array s...
Definition: Array.cs:2384
Represents a non-generic collection of objects that can be individually accessed by index.
Definition: IList.cs:8
void RemoveAt(int index)
Removes the T:System.Collections.IList item at the specified index.
static void Sort(Array array, IComparer comparer)
Sorts the elements in a one-dimensional T:System.Array using the specified T:System....
Definition: Array.cs:3347
static int IndexOf< T >(T[] array, T value)
Searches for the specified object and returns the index of its first occurrence in a one-dimensional ...
Definition: Array.cs:2875
void Insert(int index, object value)
Inserts an item to the T:System.Collections.IList at the specified index.
static int BinarySearch(Array array, int index, int length, object value)
Searches a range of elements in a one-dimensional sorted array for a value, using the T:System....
Definition: Array.cs:2090
static void Reverse(Array array)
Reverses the sequence of the elements in the entire one-dimensional T:System.Array.
Definition: Array.cs:3171
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
void SetValue(object value, long index1, long index2, long index3)
Sets a value to the element at the specified position in the three-dimensional T:System....
Definition: Array.cs:1765
abstract Type UnderlyingSystemType
Indicates the type provided by the common language runtime that represents this type.
Definition: Type.cs:816
void SetValue(object value, long index1, long index2)
Sets a value to the element at the specified position in the two-dimensional T:System....
Definition: Array.cs:1741
static T FindLast< T >(T[] array, Predicate< T > match)
Searches for an element that matches the conditions defined by the specified predicate,...
Definition: Array.cs:2591
static void Sort(Array keys, Array items, int index, int length)
Sorts a range of elements in a pair of one-dimensional T:System.Array objects (one contains the keys ...
Definition: Array.cs:3329
object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Array.
Definition: Array.cs:874
long GetLongLength(int dimension)
Gets a 64-bit integer that represents the number of elements in the specified dimension of the T:Syst...
Definition: Array.cs:1847
void Clear()
Removes all items from the T:System.Collections.IList.
int IndexOf(object value)
Determines the index of a specific item in the T:System.Collections.IList.
void Initialize()
Initializes every element of the value-type T:System.Array by calling the default constructor of the ...
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
static void Sort< T >(T[] array)
Sorts the elements in an entire T:System.Array using the T:System.IComparable`1 generic interface imp...
Definition: Array.cs:3485
int Rank
Gets the rank (number of dimensions) of the T:System.Array. For example, a one-dimensional array retu...
Definition: Array.cs:852
int GetHashCode(IEqualityComparer comparer)
Returns a hash code for the current instance.
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
static unsafe Array CreateInstance(Type elementType, int length1, int length2)
Creates a two-dimensional T:System.Array of the specified T:System.Type and dimension lengths,...
Definition: Array.cs:1007
unsafe object GetValue(int index1, int index2)
Gets the value at the specified position in the two-dimensional T:System.Array. The indexes are speci...
Definition: Array.cs:1484
static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
Copies a range of elements from an T:System.Array starting at the specified source index and pastes t...
Definition: Array.cs:1345
int Compare(object x, object y)
Compares two objects and returns a value indicating whether one is less than, equal to,...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
new bool Equals(object x, object y)
Determines whether the specified objects are equal.
static Array CreateInstance(Type elementType, params long[] lengths)
Creates a multidimensional T:System.Array of the specified T:System.Type and dimension lengths,...
Definition: Array.cs:1139
Describes objects that contain both a managed pointer to a location and a runtime representation of t...
static int LastIndexOf(Array array, object value, int startIndex, int count)
Searches for the specified object and returns the index of the last occurrence within the range of el...
Definition: Array.cs:3000
static void Sort(Array array)
Sorts the elements in an entire one-dimensional T:System.Array using the T:System....
Definition: Array.cs:3259
static int BinarySearch< T >(T[] array, T value)
Searches an entire one-dimensional sorted array for a specific element, using the T:System....
Definition: Array.cs:2249
Represents a collection that can contain many different types of permissions.
object GetValue(long index1, long index2, long index3)
Gets the value at the specified position in the three-dimensional T:System.Array. The indexes are spe...
Definition: Array.cs:1567
static ReadOnlyCollection< T > AsReadOnly< T >(T[] array)
Returns a read-only wrapper for the specified array.
Definition: Array.cs:920
The exception that is thrown when an attempt is made to access an element of an array or collection w...
int GetLowerBound(int dimension)
Gets the index of the first element of the specified dimension in the array.
void CopyTo(Array array, long index)
Copies all the elements of the current one-dimensional array to the specified one-dimensional array s...
Definition: Array.cs:2406
unsafe void SetValue(object value, int index)
Sets a value to the element at the specified position in the one-dimensional T:System....
Definition: Array.cs:1625
static int FindIndex< T >(T[] array, Predicate< T > match)
Searches for an element that matches the conditions defined by the specified predicate,...
Definition: Array.cs:2508
Defines methods to support the comparison of objects for equality.
static readonly Comparer Default
Represents an instance of T:System.Collections.Comparer that is associated with the P:System....
Definition: Comparer.cs:16
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition: ICloneable.cs:7
Exposes a method that compares two objects.
Definition: IComparer.cs:8
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
static void ForEach< T >(T[] array, Action< T > action)
Performs the specified action on each element of the specified array.
Definition: Array.cs:2708
void SetValue(object value, params long[] indices)
Sets a value to the element at the specified position in the multidimensional T:System....
Definition: Array.cs:1792
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
unsafe object GetValue(params int[] indices)
Gets the value at the specified position in the multidimensional T:System.Array. The indexes are spec...
Definition: Array.cs:1440
static int BinarySearch(Array array, int index, int length, object value, IComparer comparer)
Searches a range of elements in a one-dimensional sorted array for a value, using the specified T:Sys...
Definition: Array.cs:2144
int Add(object value)
Adds an item to the T:System.Collections.IList.
bool IsFixedSize
Gets a value indicating whether the T:System.Array has a fixed size.
Definition: Array.cs:882
MethodImplOptions
Defines the details of how a method is implemented.
static void Sort(Array array, int index, int length, IComparer comparer)
Sorts the elements in a range of elements in a one-dimensional T:System.Array using the specified T:S...
Definition: Array.cs:3401
static int BinarySearch(Array array, object value)
Searches an entire one-dimensional sorted array for a specific element, using the T:System....
Definition: Array.cs:2060
static bool Exists< T >(T[] array, Predicate< T > match)
Determines whether the specified array contains elements that match the conditions defined by the spe...
Definition: Array.cs:2435
object Clone()
Creates a shallow copy of the T:System.Array.
Definition: Array.cs:1954
int GetUpperBound(int dimension)
Gets the index of the last element of the specified dimension in the array.
static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
Creates a multidimensional T:System.Array of the specified T:System.Type and dimension lengths,...
Definition: Array.cs:1180
int GetHashCode(object obj)
Returns a hash code for the specified object.
The exception that is thrown when one of the arguments provided to a method is not valid.
unsafe void SetValue(object value, int index1, int index2)
Sets a value to the element at the specified position in the two-dimensional T:System....
Definition: Array.cs:1645
static void Sort(Array keys, Array items)
Sorts a pair of one-dimensional T:System.Array objects (one contains the keys and the other contains ...
Definition: Array.cs:3280
object GetValue(params long[] indices)
Gets the value at the specified position in the multidimensional T:System.Array. The indexes are spec...
Definition: Array.cs:1592
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
static int IndexOf(Array array, object value, int startIndex)
Searches for the specified object in a range of elements of a one-dimensional array,...
Definition: Array.cs:2770
static int FindLastIndex< T >(T[] array, Predicate< T > match)
Searches for an element that matches the conditions defined by the specified predicate,...
Definition: Array.cs:2620
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition: List.cs:14
static int LastIndexOf< T >(T[] array, T value)
Searches for the specified object and returns the index of the last occurrence within the entire T:Sy...
Definition: Array.cs:3086
static int IndexOf(Array array, object value)
Searches for the specified object and returns the index of its first occurrence in a one-dimensional ...
Definition: Array.cs:2747
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
static int IndexOf(Array array, object value, int startIndex, int count)
Searches for the specified object in a range of elements of a one-dimensional array,...
Definition: Array.cs:2797
static unsafe Array CreateInstance(Type elementType, params int[] lengths)
Creates a multidimensional T:System.Array of the specified T:System.Type and dimension lengths,...
Definition: Array.cs:1093
object GetValue(long index1, long index2)
Gets the value at the specified position in the two-dimensional T:System.Array. The indexes are speci...
Definition: Array.cs:1545
int CompareTo(object other, IComparer comparer)
Determines whether the current collection object precedes, occurs in the same position as,...
IEnumerator GetEnumerator()
Returns an T:System.Collections.IEnumerator for the T:System.Array.
Definition: Array.cs:2727
int Length
Gets the total number of elements in all the dimensions of the T:System.Array.
Definition: Array.cs:829
object GetValue(long index)
Gets the value at the specified position in the one-dimensional T:System.Array. The index is specifie...
Definition: Array.cs:1529
Specifies that the class can be serialized.
static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
Copies a range of elements from an T:System.Array starting at the specified source index and pastes t...
Definition: Array.cs:1312
static void Sort< TKey, TValue >(TKey[] keys, TValue[] items)
Sorts a pair of T:System.Array objects (one contains the keys and the other contains the correspondin...
Definition: Array.cs:3507
static int BinarySearch(Array array, object value, IComparer comparer)
Searches an entire one-dimensional sorted array for a value using the specified T:System....
Definition: Array.cs:2111
The exception that is thrown when a method call is invalid for the object's current state.
unsafe void SetValue(object value, params int[] indices)
Sets a value to the element at the specified position in the multidimensional T:System....
Definition: Array.cs:1696
void Remove(object value)
Removes the first occurrence of a specific object from the T:System.Collections.IList.
static T [] Empty< T >()
Returns an empty array.
Definition: Array.cs:2420
static int LastIndexOf(Array array, object value)
Searches for the specified object and returns the index of the last occurrence within the entire one-...
Definition: Array.cs:2950
bool Contains(object value)
Determines whether the T:System.Collections.IList contains a specific value.
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
unsafe object GetValue(int index1, int index2, int index3)
Gets the value at the specified position in the three-dimensional T:System.Array. The indexes are spe...
Definition: Array.cs:1507
int GetLength(int dimension)
Gets a 32-bit integer that represents the number of elements in the specified dimension of the T:Syst...
int Count
Gets the number of elements contained in the T:System.Collections.ICollection.
Definition: ICollection.cs:14
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
void SetValue(object value, long index)
Sets a value to the element at the specified position in the one-dimensional T:System....
Definition: Array.cs:1723
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
static T [] FindAll< T >(T[] array, Predicate< T > match)
Retrieves all the elements that match the conditions defined by the specified predicate.
Definition: Array.cs:2478
long LongLength
Gets a 64-bit integer that represents the total number of elements in all the dimensions of the T:Sys...
Definition: Array.cs:841
The exception that is thrown when an array with the wrong number of dimensions is passed to a method.
static void Sort(Array keys, Array items, int index, int length, IComparer comparer)
Sorts a range of elements in a pair of one-dimensional T:System.Array objects (one contains the keys ...
Definition: Array.cs:3431
The default setting for this enumeration, which is currently F:System.GCCollectionMode....
Defines methods to support the comparison of objects for structural equality.
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
Supports the structural comparison of collection objects.
static unsafe Array CreateInstance(Type elementType, int length1, int length2, int length3)
Creates a three-dimensional T:System.Array of the specified T:System.Type and dimension lengths,...
Definition: Array.cs:1047
unsafe object GetValue(int index)
Gets the value at the specified position in the one-dimensional T:System.Array. The index is specifie...
Definition: Array.cs:1466
static unsafe Array CreateInstance(Type elementType, int length)
Creates a one-dimensional T:System.Array of the specified T:System.Type and length,...
Definition: Array.cs:972
static TOutput [] ConvertAll< TInput, TOutput >(TInput[] array, Converter< TInput, TOutput > converter)
Converts an array of one type to an array of another type.
Definition: Array.cs:2353
bool IsSynchronized
Gets a value indicating whether access to the T:System.Array is synchronized (thread safe).
Definition: Array.cs:886
static void Sort(Array keys, Array items, IComparer comparer)
Sorts a pair of one-dimensional T:System.Array objects (one contains the keys and the other contains ...
Definition: Array.cs:3372