Wed Feb 24 15:47:16 CET 2010 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
1 // ArrayTest.cs - NUnit Test Cases for the System.Array class
2 //
3 // David Brandt (bucky@keystreams.com)
4 // Eduardo Garcia (kiwnix@yahoo.es)
5 // 
6 // (C) Ximian, Inc.  http://www.ximian.com
7 // Copyright (C) 2004 Novell (http://www.novell.com)
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 using System.Globalization;
14
15 #if NET_2_0
16 using System.Collections.Generic;
17 #endif
18
19 namespace MonoTests.System
20 {
21         //Auxiliary Things
22         enum enua  {hola,adios,mas,menos};
23
24         class AClass
25         {
26                 public AClass()
27                 {
28
29                 }
30         }
31
32         class BClass : AClass
33         {
34         }
35
36         class CClass : AClass
37         {
38         }
39
40         struct AStruct
41         {
42                 public string s;
43                 public string a;
44         }
45         
46         class DataEqual
47         {
48                 public override bool Equals (object obj)
49                 {
50                         return true;
51                 }
52         }
53                 
54         //End Auxiliary Things
55
56 [TestFixture]
57 public class ArrayTest
58 {
59         char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
60
61         public ArrayTest() {}
62
63         [Test]
64         public void TestIsFixedSize() {
65                 char[] a1 = {'a'};
66                 Assert.IsTrue (a1.IsFixedSize, "All arrays are fixed");
67         }
68         
69         [Test]
70         public void TestIsReadOnly() {
71                 char[] a1 = {'a'};
72                 Assert.IsTrue (!a1.IsReadOnly, "No array is readonly");
73         }
74
75         [Test]
76         public void TestIsSynchronized() {
77                 char[] a1 = {'a'};
78                 Assert.IsTrue (!a1.IsSynchronized, "No array is synchronized");
79         }
80
81         [Test]
82         public void TestLength() {
83                 {
84                         char[] a1 = { };
85                         Assert.AreEqual (0, a1.Length, "Zero length array");
86                 }
87                 {
88                         char[] a1 = {'c'};
89                         Assert.AreEqual (1, a1.Length, "One-length array");
90                 }
91                 {
92                         char[] a1 = {'c', 'c'};
93                         Assert.AreEqual (2, a1.Length, "Two-length array");
94                 }
95         }
96
97         [Test]
98         public void TestRank() {
99                 char[] a1 = { 'c', 'd', 'e' };
100                 Assert.AreEqual (1, a1.Rank, "Rank one");
101
102                 char[,] a2 = new Char[3,3];
103                 Assert.AreEqual (2, a2.Rank, "Rank two");
104
105                 char[,,] a3 = new Char[3,3,3];
106                 Assert.AreEqual (3, a3.Rank, "Rank three");
107         }
108
109         [Test]
110         public void TestBinarySearch1() {
111                 bool errorThrown = false;
112                 try {
113                         Array.BinarySearch(null, "blue");
114                 } catch (ArgumentNullException) {
115                         errorThrown = true;
116                 }
117                 Assert.IsTrue (errorThrown, "#B01");
118                 errorThrown = false;
119                 try {
120                         char[,] c1 = new Char[2,2];
121                         Array.BinarySearch(c1, "needle");
122                 } catch (RankException) {
123                         errorThrown = true;
124                 }
125                 Assert.IsTrue (errorThrown, "#B02");
126
127                 {
128                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
129                         Assert.IsTrue (Array.BinarySearch(arr, 'c') >= 3, "#B05");
130                         Assert.IsTrue (Array.BinarySearch(arr, 'c') < 6, "#B06");
131                 }
132                 {
133                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
134                         Assert.AreEqual (-4, Array.BinarySearch(arr, 'c'), "#B07");
135                 }
136                 {
137                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
138                         Assert.AreEqual (-9, Array.BinarySearch(arr, 'e'), "#B08");
139                 }
140         }
141
142         [Test]
143         public void TestBinarySearch2() {
144                 bool errorThrown = false;
145                 try {
146                         Array.BinarySearch(null, 0, 1, "blue");
147                 } catch (ArgumentNullException) {
148                         errorThrown = true;
149                 }
150                 Assert.IsTrue (errorThrown, "#B20");
151                 errorThrown = false;
152                 try {
153                         char[,] c1 = new Char[2,2];
154                         Array.BinarySearch(c1, 0, 1, "needle");
155                 } catch (RankException) {
156                         errorThrown = true;
157                 }
158                 Assert.IsTrue (errorThrown, "#B21");
159                 errorThrown = false;
160                 try {
161                         char[] c1 = {'a'};
162                         Array.BinarySearch(c1, -1, 1, 'a');
163                 } catch (ArgumentOutOfRangeException) {
164                         errorThrown = true;
165                 }
166                 Assert.IsTrue (errorThrown, "#B22");
167                 errorThrown = false;
168                 try {
169                         char[] c1 = {'a'};
170                         Array.BinarySearch(c1, 0, -1, 'a');
171                 } catch (ArgumentOutOfRangeException) {
172                         errorThrown = true;
173                 }
174                 Assert.IsTrue (errorThrown, "#B23");
175                 errorThrown = false;
176                 try {
177                         char[] c1 = {'a'};
178                         Array.BinarySearch(c1, 0, 4, 'a');
179                 } catch (ArgumentException) {
180                         errorThrown = true;
181                 }
182                 Assert.IsTrue (errorThrown, "#B24");
183
184                 {
185                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
186                         Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') >= 5, "#B26");
187                         Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') < 8, "#B27");
188                 }
189                 {
190                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
191                         Assert.AreEqual (-6, Array.BinarySearch(arr, 2, 8, 'c'), "#B28");
192                 }
193                 {
194                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
195                         Assert.AreEqual (-11, Array.BinarySearch(arr, 2, 8, 'e'), "#B29");
196                 }
197         }
198
199         public void TestBinarySearch3()
200         {
201                 int[] array = new int[100];
202
203                 for (int i = 0; i < 100; i++)
204                         array[i] = 10;
205
206                 Assert.AreEqual (49, Array.BinarySearch(array, 10), "#B30");
207         }
208
209         [Test]
210         public void BinarySearch_NullValue () 
211         {
212                 int[] array = new int[1];
213                 Assert.AreEqual (-1, Array.BinarySearch (array, null), "I=a,o");
214                 Assert.AreEqual (-1, Array.BinarySearch (array, null, null), "I=a,o,c");
215                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null), "I=a,i,i,o");
216                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null, null), "I=a,i,i,o,c");
217
218                 object[] o = new object [3] { this, this, null };
219                 Assert.AreEqual (-1, Array.BinarySearch (o, null), "O=a,o");
220                 Assert.AreEqual (-1, Array.BinarySearch (o, null, null), "O=a,o,c");
221                 Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null), "O=a,i,i,o");
222                 Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null, null), "O=a,i,i,o,c");
223         }
224
225         // TODO - testBinarySearch with explicit IComparer args
226
227         [Test]
228         public void TestClear() {
229                 bool errorThrown = false;
230                 try {
231                         Array.Clear(null, 0, 1);
232                 } catch (ArgumentNullException) {
233                         errorThrown = true;
234                 }
235                 Assert.IsTrue (errorThrown, "#C01");
236
237                 int[] i1 = { 1, 2, 3, 4 };
238                 {
239                         int[] compare = {1,2,3,4};
240                         Assert.AreEqual (compare[0], i1[0], "#C02");
241                         Assert.AreEqual (compare[1], i1[1], "#C03");
242                         Assert.AreEqual (compare[2], i1[2], "#C04");
243                         Assert.AreEqual (compare[3], i1[3], "#C05");
244                 }
245                 Array.Clear(i1, 3, 1);
246                 {
247                         int[] compare = {1,2,3,0};
248                         Assert.AreEqual (compare[0], i1[0], "#C06");
249                         Assert.AreEqual (compare[1], i1[1], "#C07");
250                         Assert.AreEqual (compare[2], i1[2], "#C08");
251                         Assert.AreEqual (compare[3], i1[3], "#C09");
252                 }
253                 Array.Clear(i1, 1, 1);
254                 {
255                         int[] compare = {1,0,3,0};
256                         Assert.AreEqual (compare[0], i1[0], "#C10");
257                         Assert.AreEqual (compare[1], i1[1], "#C11");
258                         Assert.AreEqual (compare[2], i1[2], "#C12");
259                         Assert.AreEqual (compare[3], i1[3], "#C13");
260                 }
261                 Array.Clear(i1, 1, 3);
262                 {
263                         int[] compare = {1,0,0,0};
264                         Assert.AreEqual (compare[0], i1[0], "#C14");
265                         Assert.AreEqual (compare[1], i1[1], "#C15");
266                         Assert.AreEqual (compare[2], i1[2], "#C16");
267                         Assert.AreEqual (compare[3], i1[3], "#C17");
268                 }
269
270                 string[] s1 = { "red", "green", "blue" };
271                 Array.Clear(s1, 0, 3);
272                 {
273                         string[] compare = {null, null, null};
274                         Assert.AreEqual (compare[0], s1[0], "#C18");
275                         Assert.AreEqual (compare[1], s1[1], "#C19");
276                         Assert.AreEqual (compare[2], s1[2], "#C20");
277                 }
278         }
279
280         [Test]
281         public void TestClone() {
282                 char[] c1 = {'a', 'b', 'c'};
283                 char[] c2 = (char[])c1.Clone();
284                 Assert.AreEqual (c1[0], c2[0], "#D01");
285                 Assert.AreEqual (c1[1], c2[1], "#D02");
286                 Assert.AreEqual (c1[2], c2[2], "#D03");
287
288                 char[] d10 = {'a', 'b'};
289                 char[] d11 = {'a', 'c'};
290                 char[] d12 = {'b', 'c'};
291                 char[][] d1 = {d10, d11, d12};
292                 char[][] d2 = (char[][])d1.Clone();
293                 Assert.AreEqual (d1[0], d2[0], "#D04");
294                 Assert.AreEqual (d1[1], d2[1], "#D05");
295                 Assert.AreEqual (d1[2], d2[2], "#D06");
296
297                 d1[0][0] = 'z';
298                 Assert.AreEqual (d1[0], d2[0], "#D07");
299         }
300
301         [Test] public void TestIndexer ()
302         {
303                 int [] a = new int [10];
304                 IList b = a;
305                 try {
306                         object c = b [-1];
307                         Assert.Fail ("IList.this [-1] should throw");
308                 } catch (IndexOutOfRangeException) {
309                         // Good
310                 } catch (Exception){
311                         Assert.Fail ("Should have thrown an IndexOutOfRangeException");
312                 }
313         }
314                 
315         [Test]
316         public void TestCopy() {
317                 {
318                         bool errorThrown = false;
319                         try {
320                                 Char[] c1 = {};
321                                 Array.Copy(c1, null, 1);
322                         } catch (ArgumentNullException) {
323                                 errorThrown = true;
324                         }
325                         Assert.IsTrue (errorThrown, "#E01");
326                 }
327                 {
328                         bool errorThrown = false;
329                         try {
330                                 Char[] c1 = {};
331                                 Array.Copy(null, c1, 1);
332                         } catch (ArgumentNullException) {
333                                 errorThrown = true;
334                         }
335                         Assert.IsTrue (errorThrown, "#E02");
336                 }
337                 {
338                         bool errorThrown = false;
339                         try {
340                                 Char[] c1 = new Char[1];
341                                 Char[,] c2 = new Char[1,1];
342                                 Array.Copy(c1, c2, 1);
343                         } catch (RankException) {
344                                 errorThrown = true;
345                         }
346                         Assert.IsTrue (errorThrown, "#E03");
347                 }
348                 {
349                         bool errorThrown = false;
350                         try {
351                                 Char[] c1 = new Char[1];
352                                 string[] s1 = new String[1];
353                                 Array.Copy(c1, s1, 1);
354                         } catch (ArrayTypeMismatchException) {
355                                 errorThrown = true;
356                         }
357                         Assert.IsTrue (errorThrown, "#E04");
358                 }
359                 {
360                         bool errorThrown = false;
361                         try {
362                                 Char[] c1 = new Char[1];
363                                 Object[] o1 = new Object[1];
364                                 o1[0] = "hello";
365                                 Array.Copy(o1, c1, 1);
366                         } catch (InvalidCastException) {
367                                 errorThrown = true;
368                         }
369                         Assert.IsTrue (errorThrown, "#E05");
370                 }
371                 {
372                         bool errorThrown = false;
373                         try {
374                                 Char[] c1 = new Char[1];
375                                 Char[] c2 = new Char[1];
376                                 Array.Copy(c1, c2, -1);
377                         } catch (ArgumentOutOfRangeException) {
378                                 errorThrown = true;
379                         }
380                         Assert.IsTrue (errorThrown, "#E06");
381                 }
382                 {
383                         bool errorThrown = false;
384                         try {
385                                 Char[] c1 = new Char[1];
386                                 Char[] c2 = new Char[2];
387                                 Array.Copy(c1, c2, 2);
388                         } catch (ArgumentException) {
389                                 errorThrown = true;
390                         }
391                         Assert.IsTrue (errorThrown, "#E07");
392                 }
393                 {
394                         bool errorThrown = false;
395                         try {
396                                 Char[] c1 = new Char[1];
397                                 Char[] c2 = new Char[2];
398                                 Array.Copy(c2, c1, 2);
399                         } catch (ArgumentException) {
400                                 errorThrown = true;
401                         }
402                         Assert.IsTrue (errorThrown, "#E08");
403                 }
404
405                 char[] orig = {'a', 'b', 'd', 'a'};
406                 char[] copy = new Char[4];
407                 Array.Copy(orig, copy, 4);
408                 for (int i = 0; i < orig.Length; i++) {
409                         Assert.AreEqual (orig[i], copy[i], "#E09(" + i + ")");
410                 }
411                 Array.Clear(copy, 0, copy.Length);
412                 for (int i = 0; i < orig.Length; i++) {
413                         Assert.AreEqual ((char)0, copy[i], "#E10(" + i + ")");
414                 }
415                 Array.Copy(orig, copy, 2);
416                 Assert.AreEqual (orig[0], copy[0], "#E11");
417                 Assert.AreEqual (orig[1], copy[1], "#E12");
418                 Assert.IsTrue (orig[2] != copy[2], "#E13");
419                 Assert.IsTrue (orig[3] != copy[3], "#E14");
420         }
421
422         [Test]
423         public void TestCopy2() {
424                 {
425                         bool errorThrown = false;
426                         try {
427                                 Char[] c1 = new Char[2];
428                                 Char[] c2 = new Char[2];
429                                 Array.Copy(c2, 1, c1, 0, 2);
430                         } catch (ArgumentException) {
431                                 errorThrown = true;
432                         }
433                         Assert.IsTrue (errorThrown, "#E31");
434                 }
435                 {
436                         bool errorThrown = false;
437                         try {
438                                 Char[] c1 = new Char[2];
439                                 Char[] c2 = new Char[2];
440                                 Array.Copy(c2, 0, c1, 1, 2);
441                         } catch (ArgumentException) {
442                                 errorThrown = true;
443                         }
444                         Assert.IsTrue (errorThrown, "#E32");
445                 }
446                 
447                 char[] orig = {'a', 'b', 'd', 'a'};
448                 char[] copy = new Char[4];
449                 Array.Copy(orig, 1, copy, 1, 3);
450                 Assert.IsTrue (copy[0] != orig[0], "#E33");
451                 for (int i = 1; i < orig.Length; i++) {
452                         Assert.AreEqual (orig[i], copy[i], "#E34(" + i + ")");
453                 }
454                 Array.Clear(copy, 0, copy.Length);
455                 Array.Copy(orig, 1, copy, 0, 2);
456                 Assert.AreEqual (orig[1], copy[0], "#E35");
457                 Assert.AreEqual (orig[2], copy[1], "#E36");
458                 Assert.IsTrue (copy[2] != orig[2], "#E37");
459                 Assert.IsTrue (copy[3] != orig[3], "#E38");
460         }
461
462         [Test]
463         [ExpectedException (typeof (InvalidCastException))]
464         public void Copy_InvalidCast () {
465                 object[] arr1 = new object [10];
466                 Type[] arr2 = new Type [10];
467
468                 arr1 [0] = new object ();
469
470                 Array.Copy (arr1, 0, arr2, 0, 10);
471         }
472
473         [Test]
474         public void TestCopyTo() {
475                 {
476                         bool errorThrown = false;
477                         try {
478                                 Char[] c1 = new Char[2];
479                                 c1.CopyTo(null, 2);
480                         } catch (ArgumentNullException) {
481                                 errorThrown = true;
482                         }
483                         Assert.IsTrue (errorThrown, "#E61");
484                 }
485                 {
486                         bool errorThrown = false;
487                         try {
488                                 Char[] c1 = new Char[2];
489                                 Char[,] c2 = new Char[2,2];
490                                 c1.CopyTo(c2, 2);
491                         } catch (ArgumentException) {
492                                 errorThrown = true;
493                         }
494 #if TARGET_JVM // This is really implementation dependent behaviour.
495                         catch (RankException) {
496                                 errorThrown = true;
497                         }
498 #endif // TARGET_JVM
499                         Assert.IsTrue (errorThrown, "#E62");
500                 }
501                 {
502                         bool errorThrown = false;
503                         try {
504                                 Char[,] c1 = new Char[2,2];
505                                 Char[] c2 = new Char[2];
506                                 c1.CopyTo(c2, -1);
507                         } catch (RankException) {
508                                 errorThrown = true;
509                         }
510                         Assert.IsTrue (errorThrown, "#E63");
511                 }
512                 {
513                         bool errorThrown = false;
514                         try {
515                                 Char[,] c1 = new Char[2,2];
516                                 Char[] c2 = new Char[2];
517                                 c1.CopyTo(c2, 2);
518                         } catch (RankException) {
519                                 errorThrown = true;
520                         }
521                         Assert.IsTrue (errorThrown, "#E64");
522                 }
523                 {
524                         bool errorThrown = false;
525                         try {
526                                 Char[] c1 = new Char[2];
527                                 Char[] c2 = new Char[2];
528                                 c1.CopyTo(c2, -1);
529                         } catch (ArgumentOutOfRangeException) {
530                                 errorThrown = true;
531                         }
532                         Assert.IsTrue (errorThrown, "#E65");
533                 }
534                 {
535                         bool errorThrown = false;
536                         try {
537                                 Char[] c1 = new Char[2];
538                                 Char[] c2 = new Char[2];
539                                 c1.CopyTo(c2, 3);
540                         } catch (ArgumentException) {
541                                 errorThrown = true;
542                         }
543                         Assert.IsTrue (errorThrown, "#E66");
544                 }
545                 {
546                         bool errorThrown = false;
547                         try {
548                                 Char[] c1 = new Char[2];
549                                 Char[] c2 = new Char[2];
550                                 c1.CopyTo(c2, 1);
551                         } catch (ArgumentException) {
552                                 errorThrown = true;
553                         }
554                         Assert.IsTrue (errorThrown, "#E67");
555                 }
556
557                 {
558                         bool errorThrown = false;
559                         try {
560                                 String[] c1 = new String[2];
561                                 // TODO: this crashes mono if there are null
562                                 // values in the array.
563                                 c1[1] = "hey";
564                                 c1[0] = "you";
565                                 Char[] c2 = new Char[2];
566                                 c2[1] = 'a';
567                                 c2[0] = 'z';
568                                 c1.CopyTo(c2, 0);
569                         } catch (ArrayTypeMismatchException) {
570                                 errorThrown = true;
571                         }
572                         Assert.IsTrue (errorThrown, "#E68");
573                 }
574
575                 Char[] orig = {'a', 'b', 'c', 'd'};
576                 Char[] copy = new Char[10];
577                 Array.Clear(copy, 0, copy.Length);
578                 orig.CopyTo(copy, 3);
579                 Assert.AreEqual ((char)0, copy[0], "#E69");
580                 Assert.AreEqual ((char)0, copy[1], "#E70");
581                 Assert.AreEqual ((char)0, copy[2], "#E71");
582                 Assert.AreEqual (orig[0], copy[3], "#E72");
583                 Assert.AreEqual (orig[1], copy[4], "#E73");
584                 Assert.AreEqual (orig[2], copy[5], "#E74");
585                 Assert.AreEqual (orig[3], copy[6], "#E75");
586                 Assert.AreEqual ((char)0, copy[7], "#E76");
587                 Assert.AreEqual ((char)0, copy[8], "#E77");
588                 Assert.AreEqual ((char)0, copy[9], "#E78");
589
590                 {
591                         // The following is valid and must not throw an exception.
592                         bool errorThrown = false;
593                         try {
594                                 int[] src = new int [0];
595                                 int[] dest = new int [0];
596                                 src.CopyTo (dest, 0);
597                         } catch (ArgumentException) {
598                                 errorThrown = true;
599                         }
600                         Assert.IsTrue (!errorThrown, "#E79");
601                 }
602
603                 {
604                         // bug #38812
605                         bool errorThrown = false;
606                         try {
607                                 CClass[] src = new CClass [] { new CClass () };
608                                 BClass[] dest = new BClass [1];
609
610                                 src.CopyTo (dest, 0);
611
612                         } catch (ArrayTypeMismatchException) {
613                                 errorThrown = true;
614                         }
615                         Assert.IsTrue (errorThrown, "#E80");
616                 }
617         }
618
619         [Test]
620         public void TestCreateInstance() {
621                 {
622                         bool errorThrown = false;
623                         try {
624                                 Array.CreateInstance(null, 12);
625                         } catch (ArgumentNullException) {
626                                 errorThrown = true;
627                         }
628                         Assert.IsTrue (errorThrown, "#F01");
629                 }
630                 {
631                         bool errorThrown = false;
632                         try {
633                                 Array.CreateInstance(Type.GetType("System.Char"), -3);
634                         } catch (ArgumentOutOfRangeException) {
635                                 errorThrown = true;
636                         }
637                         Assert.IsTrue (errorThrown, "#F02");
638                 }
639                 {
640                         bool errorThrown = false;
641                         try {
642                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
643                         } catch (ArgumentNullException) {
644                                 errorThrown = true;
645                         }
646                         Assert.IsTrue (errorThrown, "#F03a");
647                 }
648 #if NET_1_1
649                 {
650                         bool errorThrown = false;
651                         try {
652                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
653                         } catch (ArgumentNullException) {
654                                 errorThrown = true;
655                         }
656                         Assert.IsTrue (errorThrown, "#F03b");
657                 }
658 #endif
659 #if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
660                 {
661                         bool errorThrown = false;
662                         try {
663                                 Array.CreateInstance(Type.GetType("System.Char"), null, null);
664                         } catch (ArgumentNullException) {
665                                 errorThrown = true;
666                         }
667                         Assert.IsTrue (errorThrown, "#F04");
668                 }
669 #endif // TARGET_JVM
670                 {
671                         bool errorThrown = false;
672                         try {
673                                 int[] lengths = new int [0];
674                                 Array.CreateInstance(Type.GetType("System.Char"), lengths);
675                         } catch (ArgumentException) {
676                                 errorThrown = true;
677                         }
678                         Assert.IsTrue (errorThrown, "#F05");
679                 }
680 #if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
681                 {
682                         bool errorThrown = false;
683                         try {
684                                 int[] lengths = new int [1];
685                                 int[] bounds = new int [2];
686                                 Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
687                                 errorThrown = true;
688                         } catch (ArgumentException) {
689                                 errorThrown = true;
690                         }
691                         Assert.IsTrue (errorThrown, "#F06");
692                 }
693
694                 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
695                 Assert.AreEqual (12, c1.Length, "#F07");
696
697                 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
698                 Assert.AreEqual (2, c2.Rank, "#F08");
699                 Assert.AreEqual (60, c2.Length, "#F09");
700
701
702                 {
703                         int[] lengths = { 3 };
704                         int[] bounds = { 5 };
705                         int[] src = { 512, 718, 912 };
706                         Array array = Array.CreateInstance(typeof(int), lengths, bounds);
707
708                         Assert.AreEqual (3, array.Length, "#F10");
709                         Assert.AreEqual (5, array.GetLowerBound(0), "#F11");
710                         Assert.AreEqual (7, array.GetUpperBound(0), "#F12");
711
712                         src.CopyTo (array, 5);
713
714                         for (int i = 0; i < src.Length; i++)
715                                 Assert.AreEqual (src[i], array.GetValue(i+5), "#F13(" + i + ")");
716                 }
717
718                 // Test that a 1 dimensional array with 0 lower bound is the
719                 // same as an szarray
720                 Type szarrayType = new int [10].GetType ();
721                 Assert.IsTrue (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
722                 Assert.IsTrue (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
723 #endif // TARGET_JVM
724         }
725         
726         [Test]
727         [ExpectedException (typeof (ArgumentNullException))]
728         public void TestCreateInstance2 ()
729         {
730                 Array.CreateInstance (typeof (Int32), (int[])null);
731         }
732
733         [Test]
734 #if NET_2_0
735         [ExpectedException (typeof (ArgumentNullException))]
736 #else
737         [ExpectedException (typeof (NullReferenceException))]
738 #endif
739         public void TestCreateInstance2b ()
740         {
741                 Array.CreateInstance (typeof (Int32), (long[])null);
742         }
743
744         [Test]
745         public void TestGetEnumerator() {
746                 String[] s1 = {"this", "is", "a", "test"};
747                 IEnumerator en = s1.GetEnumerator ();
748                 Assert.IsNotNull (en, "#G01");
749
750                 Assert.IsTrue (en.MoveNext (), "#G02");
751                 Assert.AreEqual ("this", en.Current, "#G03");
752                 Assert.IsTrue (en.MoveNext (), "#G04");
753                 Assert.AreEqual ("is", en.Current, "#G05");
754                 Assert.IsTrue (en.MoveNext (), "#G06");
755                 Assert.AreEqual ("a", en.Current, "#G07");
756                 Assert.IsTrue (en.MoveNext (), "#G08");
757                 Assert.AreEqual ("test", en.Current, "#G09");
758                 Assert.IsTrue (!en.MoveNext (), "#G10");
759
760                 en.Reset ();
761                 Assert.IsTrue (en.MoveNext (), "#G11");
762                 Assert.AreEqual ("this", en.Current, "#G12");
763
764                 // mutation does not invalidate array enumerator!
765                 s1.SetValue ("change", 1);
766                 Assert.IsTrue (en.MoveNext (), "#G13");
767                 Assert.AreEqual ("change", en.Current, "#G14");
768         }
769
770         [Test]
771         public void TestGetEnumeratorMultipleDimension() {
772                 String[,] s1 = {{"this", "is"}, {"a", "test"}};
773                 IEnumerator en = s1.GetEnumerator ();
774                 Assert.IsNotNull (en, "#AA01");
775
776                 Assert.IsTrue (en.MoveNext (), "#AA02");
777                 Assert.AreEqual ("this", en.Current, "#AA03");
778                 Assert.IsTrue (en.MoveNext (), "#AA04");
779                 Assert.AreEqual ("is", en.Current, "#AA05");
780                 Assert.IsTrue (en.MoveNext (), "#AA06");
781                 Assert.AreEqual ("a", en.Current, "#AA07");
782                 Assert.IsTrue (en.MoveNext (), "#AA08");
783                 Assert.AreEqual ("test", en.Current, "#AA09");
784                 Assert.IsTrue (!en.MoveNext (), "#AA10");
785
786                 en.Reset ();
787                 Assert.IsTrue (en.MoveNext (), "#AA11");
788                 Assert.AreEqual ("this", en.Current, "#AA12");
789
790                 int[] idxs = {0,1};
791                 // mutation does not invalidate array enumerator!
792                 s1.SetValue ("change", idxs);
793                 Assert.IsTrue (en.MoveNext (), "#AA13");
794                 Assert.AreEqual ("change", en.Current, "#AA14");
795         }
796
797         [Test]
798         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
799         public void TestGetEnumeratorNonZeroLowerBounds() {
800                 int[] myLengthsArray = new int[2] { 3, 5 };
801                 int[] myBoundsArray = new int[2] { 2, 3 };
802
803                 Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
804                 for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
805                         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {
806                                 int[] myIndicesArray = new int[2] { i, j };
807                                 myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
808                         }
809                 IEnumerator en = myArray.GetEnumerator ();
810                 Assert.IsNotNull (en, "#AB01");
811
812                 // check the first couple of values
813                 Assert.IsTrue (en.MoveNext (), "#AB02");
814                 Assert.AreEqual ("23", en.Current, "#AB03");
815                 Assert.IsTrue (en.MoveNext (), "#AB04");
816                 Assert.AreEqual ("24", en.Current, "#AB05");
817
818                 // then check the last element's value
819                 string lastElement;
820                 do {  
821                         lastElement = (string)en.Current;
822                 } while (en.MoveNext());
823                 Assert.AreEqual ("47", lastElement, "#AB06");
824         }
825
826         [Test]
827         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
828         public void TestIList_Add () {
829                 int[] myLengthsArray = new int[2] { 3, 5 };
830                 int[] myBoundsArray = new int[2] { 2, 3 };
831
832                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
833                 try {
834                         ((IList)myArray).Add ("can not");
835                         Assert.Fail ("IList.Add should throw");
836                 }
837                 catch (NotSupportedException) {
838                         return;
839                 }
840                 catch (Exception) {
841                         Assert.Fail ("IList.Add threw wrong exception type");
842                 }
843
844                 Assert.Fail ("IList.Add shouldn't get this far");
845         }
846
847         [Test]
848         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
849         public void TestIList_Insert () {
850                 int[] myLengthsArray = new int[2] { 3, 5 };
851                 int[] myBoundsArray = new int[2] { 2, 3 };
852
853                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
854                 try {
855                         ((IList)myArray).Insert (0, "can not");
856                         Assert.Fail ("IList.Insert should throw");
857                 }
858                 catch (NotSupportedException) {
859                         return;
860                 }
861                 catch (Exception) {
862                         Assert.Fail ("IList.Insert threw wrong exception type");
863                 }
864
865                 Assert.Fail ("IList.Insert shouldn't get this far");
866         }
867
868         [Test]
869         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
870         public void TestIList_Remove () {
871                 int[] myLengthsArray = new int[2] { 3, 5 };
872                 int[] myBoundsArray = new int[2] { 2, 3 };
873
874                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
875                 try {
876                         ((IList)myArray).Remove ("can not");
877                         Assert.Fail ("IList.Remove should throw");
878                 }
879                 catch (NotSupportedException) {
880                         return;
881                 }
882                 catch (Exception) {
883                         Assert.Fail ("IList.Remove threw wrong exception type");
884                 }
885
886                 Assert.Fail ("IList.Remove shouldn't get this far");
887         }
888
889         [Test]
890         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
891         public void TestIList_RemoveAt () {
892                 int[] myLengthsArray = new int[2] { 3, 5 };
893                 int[] myBoundsArray = new int[2] { 2, 3 };
894
895                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
896                 try {
897                         ((IList)myArray).RemoveAt (0);
898                         Assert.Fail ("IList.RemoveAt should throw");
899                 }
900                 catch (NotSupportedException) {
901                         return;
902                 }
903                 catch (Exception) {
904                         Assert.Fail ("IList.RemoveAt threw wrong exception type");
905                 }
906
907                 Assert.Fail ("IList.RemoveAt shouldn't get this far");
908         }
909
910         [Test]
911         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
912         public void TestIList_Contains () {
913                 int[] myLengthsArray = new int[2] { 3, 5 };
914                 int[] myBoundsArray = new int[2] { 2, 3 };
915
916                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
917
918                 try {
919                         bool b = ((IList)myArray).Contains ("23");
920                         Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
921                 }
922                 catch (RankException) {
923                         int[] iArr = new int[3] { 1, 2, 3};
924                         // check the first and last items
925                         Assert.IsTrue (((IList)iArr).Contains (1), "AC01");
926                         Assert.IsTrue (((IList)iArr).Contains (3), "AC02");
927
928                         // and one that is definately not there
929                         Assert.IsTrue (!((IList)iArr).Contains (42), "AC03");
930                         return;
931                 }
932
933                 Assert.Fail ("Should not get here");
934         }
935
936         [Test]
937         [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
938         public void TestIList_IndexOf () {
939                 int[] myLengthsArray = new int[2] { 3, 5 };
940                 int[] myBoundsArray = new int[2] { 2, 3 };
941
942                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
943
944                 try {
945                         bool b = ((IList)myArray).Contains ("23");
946                         Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
947                 }
948                 catch (RankException) {
949                         int[] iArr = new int[3] { 1, 2, 3};
950                         // check the first and last items
951                         Assert.AreEqual (0, ((IList)iArr).IndexOf (1), "AD01");
952                         Assert.AreEqual (2, ((IList)iArr).IndexOf (3), "AD02");
953
954                         // and one that is definately not there
955                         Assert.AreEqual (-1, ((IList)iArr).IndexOf (42), "AD03");
956                 }
957                 catch (Exception e) {
958                         Assert.Fail ("Unexpected exception: " + e.ToString());
959                 }
960
961                 // check that wierd case whem lowerbound is Int32.MinValue,
962                 // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
963                 int[] myLengthArray = new int[1] { 3 };
964                 int[] myBoundArray = new int[1] { Int32.MinValue };
965                 Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
966                 Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
967
968         }
969
970         [Test]
971         public void TestGetLength() {
972                 {
973                         bool errorThrown = false;
974                         try {
975                                 char[] c1 = {'a', 'b', 'c'};
976                                 c1.GetLength(-1);
977                         } catch (IndexOutOfRangeException) {
978                                 errorThrown = true;
979                         }
980                         Assert.IsTrue (errorThrown, "#H01");
981                 }
982                 {
983                         bool errorThrown = false;
984                         try {
985                                 char[] c1 = {'a', 'b', 'c'};
986                                 c1.GetLength(1);
987                         } catch (IndexOutOfRangeException) {
988                                 errorThrown = true;
989                         }
990                         Assert.IsTrue (errorThrown, "#H02");
991                 }
992
993                 char[] c2 = new Char[5];
994                 Assert.AreEqual (5, c2.GetLength(0), "#H03");
995
996                 char[,] c3 = new Char[6,7];
997                 Assert.AreEqual (6, c3.GetLength(0), "#H04");
998                 Assert.AreEqual (7, c3.GetLength(1), "#H05");
999         }
1000
1001         [Test]
1002         public void TestGetLowerBound() {
1003                 {
1004                         bool errorThrown = false;
1005                         try {
1006                                 char[] c = {'a', 'b', 'c'};
1007                                 c.GetLowerBound(-1);
1008                         } catch (IndexOutOfRangeException) {
1009                                 errorThrown = true;
1010                         }
1011                         Assert.IsTrue (errorThrown, "#H31");
1012                 }
1013                 {
1014                         bool errorThrown = false;
1015                         try {
1016                                 char[] c = {'a', 'b', 'c'};
1017                                 c.GetLowerBound(1);
1018                         } catch (IndexOutOfRangeException) {
1019                                 errorThrown = true;
1020                         }
1021                         Assert.IsTrue (errorThrown, "#H32");
1022                 }
1023
1024                 char[] c1 = new Char[5];
1025                 Assert.AreEqual (0, c1.GetLowerBound(0), "#H33");
1026
1027                 char[,] c2 = new Char[4,4];
1028                 Assert.AreEqual (0, c2.GetLowerBound(0), "#H34");
1029                 Assert.AreEqual (0, c2.GetLowerBound(1), "#H35");
1030         }
1031
1032         [Test]
1033         public void TestGetUpperBound() {
1034                 {
1035                         bool errorThrown = false;
1036                         try {
1037                                 char[] c = {'a', 'b', 'c'};
1038                                 c.GetUpperBound(-1);
1039                         } catch (IndexOutOfRangeException) {
1040                                 errorThrown = true;
1041                         }
1042                         Assert.IsTrue (errorThrown, "#H61");
1043                 }
1044                 {
1045                         bool errorThrown = false;
1046                         try {
1047                                 char[] c = {'a', 'b', 'c'};
1048                                 c.GetUpperBound(1);
1049                         } catch (IndexOutOfRangeException) {
1050                                 errorThrown = true;
1051                         }
1052                         Assert.IsTrue (errorThrown, "#H62");
1053                 }
1054
1055                 char[] c1 = new Char[5];
1056                 Assert.AreEqual (4, c1.GetUpperBound(0), "#H63");
1057
1058                 char[,] c2 = new Char[4,6];
1059                 Assert.AreEqual (3, c2.GetUpperBound(0), "#H64");
1060                 Assert.AreEqual (5, c2.GetUpperBound(1), "#H65");
1061         }
1062
1063         [Test]
1064         public void TestGetValue1() {
1065                 {
1066                         bool errorThrown = false;
1067                         try {
1068                                 char[,] c = new Char[2,2];
1069                                 c.GetValue(1);
1070                         } catch (ArgumentException) {
1071                                 errorThrown = true;
1072                         }
1073                         Assert.IsTrue (errorThrown, "#I01");
1074                 }
1075                 {
1076                         bool errorThrown = false;
1077                         try {
1078                                 char[] c = {'a', 'b', 'c'};
1079                                 c.GetValue(-1);
1080                         } catch (IndexOutOfRangeException) {
1081                                 errorThrown = true;
1082                         }
1083                         Assert.IsTrue (errorThrown, "#I02");
1084                 }
1085                 {
1086                         bool errorThrown = false;
1087                         try {
1088                                 char[] c = {'a', 'b', 'c'};
1089                                 c.GetValue(4);
1090                         } catch (IndexOutOfRangeException) {
1091                                 errorThrown = true;
1092                         }
1093                         Assert.IsTrue (errorThrown, "#I03");
1094                 }
1095
1096                 char[] c1 = {'a', 'b', 'c', 'd'};
1097                 for (int i = 0; i < c1.Length; i++) {
1098                         Assert.AreEqual (c1[i], c1.GetValue(i), "#I04(" + i + ")");
1099                 }
1100         }
1101
1102         [Test]
1103         public void TestGetValue2() {
1104                 {
1105                         bool errorThrown = false;
1106                         try {
1107                                 char[] c = new Char[2];
1108                                 c.GetValue(1,1);
1109                         } catch (ArgumentException) {
1110                                 errorThrown = true;
1111                         }
1112                         Assert.IsTrue (errorThrown, "#I21");
1113                 }
1114                 {
1115                         bool errorThrown = false;
1116                         try {
1117                                 char[,] c = new Char[2,2];
1118                                 c.GetValue(-1, 1);
1119                         } catch (IndexOutOfRangeException) {
1120                                 errorThrown = true;
1121                         }
1122                         Assert.IsTrue (errorThrown, "#I22");
1123                 }
1124                 {
1125                         bool errorThrown = false;
1126                         try {
1127                                 char[,] c = new Char[2,2];
1128                                 c.GetValue(4,1);
1129                         } catch (IndexOutOfRangeException) {
1130                                 errorThrown = true;
1131                         }
1132                         Assert.IsTrue (errorThrown, "#I23");
1133                 }
1134
1135                 char[,] c1 = new Char[4,6];
1136                 for (int i = 0; i < 24; i++) {
1137                         int first = i / 6;
1138                         int second = i % 6;
1139                         c1[first,second] = (char)(((int)'a')+i);
1140                 }
1141                 for (int i = 0; i < c1.GetLength(0); i++) {
1142                         for (int j = 0; j < c1.GetLength(1); j++) {
1143                                 Assert.AreEqual (c1[i, j], c1.GetValue(i, j), "#I24(" + i + "," + j + ")");
1144                         }
1145                 }
1146         }
1147
1148         [Test]
1149         public void TestGetValue3() {
1150                 {
1151                         bool errorThrown = false;
1152                         try {
1153                                 char[] c = new Char[2];
1154                                 c.GetValue(1,1,1);
1155                         } catch (ArgumentException) {
1156                                 errorThrown = true;
1157                         }
1158                         Assert.IsTrue (errorThrown, "#I41");
1159                 }
1160                 {
1161                         bool errorThrown = false;
1162                         try {
1163                                 char[,,] c = new Char[2,2,2];
1164                                 c.GetValue(-1, 1, 1);
1165                         } catch (IndexOutOfRangeException) {
1166                                 errorThrown = true;
1167                         }
1168                         Assert.IsTrue (errorThrown, "#I42");
1169                 }
1170                 {
1171                         bool errorThrown = false;
1172                         try {
1173                                 char[,,] c = new Char[2,2,2];
1174                                 c.GetValue(4,1,1);
1175                         } catch (IndexOutOfRangeException) {
1176                                 errorThrown = true;
1177                         }
1178                         Assert.IsTrue (errorThrown, "#I43");
1179                 }
1180
1181                 char[,,] c1 = new Char[4,2,3];
1182                 for (int i = 0; i < 24; i++) {
1183                         int first = i / 6;
1184                         int remains = i % 6;
1185                         int second = remains / 3;
1186                         int third = remains % 3;
1187                         c1[first,second, third] = (char)(((int)'a')+i);
1188                 }
1189                 for (int i = 0; i < c1.GetLength(0); i++) {
1190                         for (int j = 0; j < c1.GetLength(1); j++) {
1191                                 for (int k = 0; k < c1.GetLength(2); k++) {
1192                                         Assert.AreEqual (c1[i, j, k], c1.GetValue(i, j, k), "#I44(" + i + "," + j + ")");
1193                                 }
1194                         }
1195                 }
1196         }
1197
1198         [Test]
1199 #if NET_2_0
1200         [ExpectedException (typeof (ArgumentNullException))]
1201 #else
1202         [ExpectedException (typeof (NullReferenceException))]
1203 #endif
1204         public void TestGetValueLongArray ()
1205         {
1206                 char[] c = new Char[2];
1207                 c.GetValue((long [])null);
1208         }
1209
1210         [Test]
1211         public void TestGetValueN() {
1212                 {
1213                         bool errorThrown = false;
1214                         try {
1215                                 char[] c = new Char[2];
1216                                 c.GetValue((int [])null);
1217                         } catch (ArgumentNullException) {
1218                                 errorThrown = true;
1219                         }
1220                         Assert.IsTrue (errorThrown, "#I61a");
1221                 }
1222                 {
1223                         bool errorThrown = false;
1224                         try {
1225                                 char[] c = new Char[2];
1226                                 int[] coords = {1, 1};
1227                                 c.GetValue(coords);
1228                         } catch (ArgumentException) {
1229                                 errorThrown = true;
1230                         }
1231                         Assert.IsTrue (errorThrown, "#I62");
1232                 }
1233                 {
1234                         bool errorThrown = false;
1235                         try {
1236                                 char[,] c = new Char[2,2];
1237                                 int[] coords = {-1, 1};
1238                                 c.GetValue(coords);
1239                         } catch (IndexOutOfRangeException) {
1240                                 errorThrown = true;
1241                         }
1242                         Assert.IsTrue (errorThrown, "#I63");
1243                 }
1244                 {
1245                         bool errorThrown = false;
1246                         try {
1247                                 char[,] c = new Char[2,2];
1248                                 int[] coords = {4, 1};
1249                                 c.GetValue(coords);
1250                         } catch (IndexOutOfRangeException) {
1251                                 errorThrown = true;
1252                         }
1253                         Assert.IsTrue (errorThrown, "#I64");
1254                 }
1255
1256                 char[,] c1 = new Char[4,6];
1257                 for (int i = 0; i < 24; i++) {
1258                         int first = i / 6;
1259                         int second = i % 6;
1260                         c1[first,second] = (char)(((int)'a')+i);
1261                 }
1262                 for (int i = 0; i < c1.GetLength(0); i++) {
1263                         for (int j = 0; j < c1.GetLength(1); j++) {
1264                                 int[] coords = {i, j};
1265                                 Assert.AreEqual (c1[i, j], c1.GetValue(coords), "#I65(" + i + "," + j + ")");
1266                         }
1267                 }
1268         }
1269
1270         [Test]
1271         public void TestIndexOf1() {
1272                 {
1273                         bool errorThrown = false;
1274                         try {
1275                                 Array.IndexOf(null, "huh?");
1276                         } catch (ArgumentNullException) {
1277                                 errorThrown = true;
1278                         }
1279                         Assert.IsTrue (errorThrown, "#J01");
1280                 }
1281                 {
1282                         bool errorThrown = false;
1283                         try {
1284                                 char[,] c = new Char[2,2];
1285                                 Array.IndexOf(c, "huh?");
1286                         } catch (RankException) {
1287                                 errorThrown = true;
1288                         }
1289                         Assert.IsTrue (errorThrown, "#J02");
1290                 }
1291
1292                 String[] s1 = {"this", "is", "a", "test"};
1293                 Assert.AreEqual (-1, Array.IndexOf(s1, null), "#J03");
1294                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing"), "#J04");
1295                 Assert.AreEqual (0, Array.IndexOf(s1, "this"), "#J05");
1296                 Assert.AreEqual (3, Array.IndexOf(s1, "test"), "#J06");
1297         }
1298
1299         [Test]
1300         public void TestIndexOf2() {
1301                 {
1302                         bool errorThrown = false;
1303                         try {
1304                                 Array.IndexOf(null, "huh?", 0);
1305                         } catch (ArgumentNullException) {
1306                                 errorThrown = true;
1307                         }
1308                         Assert.IsTrue (errorThrown, "#J21");
1309                 }
1310                 {
1311                         bool errorThrown = false;
1312                         try {
1313                                 char[,] c = new Char[2,2];
1314                                 Array.IndexOf(c, "huh?", 0);
1315                         } catch (RankException) {
1316                                 errorThrown = true;
1317                         }
1318                         Assert.IsTrue (errorThrown, "#J22");
1319                 }
1320                 {
1321                         bool errorThrown = false;
1322                         try {
1323                                 char[] c = new Char[2];
1324                                 Array.IndexOf(c, "huh?", 3);
1325                         } catch (ArgumentOutOfRangeException) {
1326                                 errorThrown = true;
1327                         }
1328                         Assert.IsTrue (errorThrown, "#J23");
1329                 }
1330
1331                 String[] s1 = {"this", "is", "really", "a", "test"};
1332                 Assert.AreEqual (-1, Array.IndexOf(s1, null, 1), "#J24");
1333                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1), "#J25");
1334                 Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1), "#J26");
1335                 Assert.AreEqual (1, Array.IndexOf(s1, "is", 1), "#J27");
1336                 Assert.AreEqual (4, Array.IndexOf(s1, "test", 1), "#J28");
1337         }
1338
1339         [Test]
1340         public void TestIndexOf3() {
1341                 {
1342                         bool errorThrown = false;
1343                         try {
1344                                 Array.IndexOf(null, "huh?", 0, 1);
1345                         } catch (ArgumentNullException) {
1346                                 errorThrown = true;
1347                         }
1348                         Assert.IsTrue (errorThrown, "#J41");
1349                 }
1350                 {
1351                         bool errorThrown = false;
1352                         try {
1353                                 char[,] c = new Char[2,2];
1354                                 Array.IndexOf(c, "huh?", 0, 1);
1355                         } catch (RankException) {
1356                                 errorThrown = true;
1357                         }
1358                         Assert.IsTrue (errorThrown, "#J42");
1359                 }
1360                 {
1361                         bool errorThrown = false;
1362                         try {
1363                                 char[] c = new Char[2];
1364                                 Array.IndexOf(c, "huh?", 3, 1);
1365                         } catch (ArgumentOutOfRangeException) {
1366                                 errorThrown = true;
1367                         }
1368                         Assert.IsTrue (errorThrown, "#J43");
1369                 }
1370                 {
1371                         bool errorThrown = false;
1372                         try {
1373                                 char[] c = new Char[2];
1374                                 Array.IndexOf(c, "huh?", 0, 5);
1375                         } catch (ArgumentOutOfRangeException) {
1376                                 errorThrown = true;
1377                         }
1378                         Assert.IsTrue (errorThrown, "#J44");
1379                 }
1380
1381                 String[] s1 = {"this", "is", "really", "a", "test"};
1382                 Assert.AreEqual (-1, Array.IndexOf(s1, null, 1, 3), "#J45");
1383                 Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1, 3), "#J46");
1384                 Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1, 3), "#J47");
1385                 Assert.AreEqual (1, Array.IndexOf(s1, "is", 1, 3), "#J48");
1386                 Assert.AreEqual (-1, Array.IndexOf(s1, "test", 1, 3), "#J49");
1387                 Assert.AreEqual (3, Array.IndexOf(s1, "a", 1, 3), "#J50");
1388         }
1389         
1390         [Test]
1391         public void TestIndexOf_CustomEqual ()
1392         {
1393                 DataEqual[] test = new DataEqual [] { new DataEqual () };
1394                 Assert.AreEqual (0, Array.IndexOf (test, "asdfas", 0));
1395                 
1396                 IList array = (IList)test;
1397                 Assert.AreEqual (0, array.IndexOf ("asdfas"));
1398         }
1399         
1400         [Test]
1401         public void TestLastIndexOf1() {
1402                 {
1403                         bool errorThrown = false;
1404                         try {
1405                                 Array.LastIndexOf(null, "huh?");
1406                         } catch (ArgumentNullException) {
1407                                 errorThrown = true;
1408                         }
1409                         Assert.IsTrue (errorThrown, "#K01");
1410                 }
1411                 {
1412                         bool errorThrown = false;
1413                         try {
1414                                 char[,] c = new Char[2,2];
1415                                 Array.LastIndexOf(c, "huh?");
1416                         } catch (RankException) {
1417                                 errorThrown = true;
1418                         }
1419                         Assert.IsTrue (errorThrown, "#K02");
1420                 }
1421
1422                 String[] s1 = {"this", "is", "a", "a", "test"};
1423                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null), "#K03");
1424                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing"), "#K04");
1425                 Assert.AreEqual (0, Array.LastIndexOf(s1, "this"), "#K05");
1426                 Assert.AreEqual (4, Array.LastIndexOf(s1, "test"), "#K06");
1427                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a"), "#K07");
1428
1429                 Assert.AreEqual (-1, Array.LastIndexOf (new String [0], "foo"));
1430         }
1431
1432         [Test]
1433         public void TestLastIndexOf2() {
1434                 {
1435                         bool errorThrown = false;
1436                         try {
1437                                 Array.LastIndexOf(null, "huh?", 0);
1438                         } catch (ArgumentNullException) {
1439                                 errorThrown = true;
1440                         }
1441                         Assert.IsTrue (errorThrown, "#K21");
1442                 }
1443                 {
1444                         bool errorThrown = false;
1445                         try {
1446                                 char[,] c = new Char[2,2];
1447                                 Array.LastIndexOf(c, "huh?", 0);
1448                         } catch (RankException) {
1449                                 errorThrown = true;
1450                         }
1451                         Assert.IsTrue (errorThrown, "#K22");
1452                 }
1453                 {
1454                         bool errorThrown = false;
1455                         try {
1456                                 char[] c = new Char[2];
1457                                 Array.LastIndexOf(c, "huh?", 3);
1458                         } catch (ArgumentOutOfRangeException) {
1459                                 errorThrown = true;
1460                         }
1461                         Assert.IsTrue (errorThrown, "#K23");
1462                 }
1463
1464                 String[] s1 = {"this", "is", "really", "a", "test"};
1465                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3), "#K24");
1466                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3), "#K25");
1467                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3), "#K26");
1468                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3), "#K27");
1469                 Assert.AreEqual (0, Array.LastIndexOf(s1, "this", 3), "#K28");
1470         }
1471
1472         [Test]
1473         public void TestLastIndexOf3() {
1474                 {
1475                         bool errorThrown = false;
1476                         try {
1477                                 Array.LastIndexOf(null, "huh?", 0, 1);
1478                         } catch (ArgumentNullException) {
1479                                 errorThrown = true;
1480                         }
1481                         Assert.IsTrue (errorThrown, "#K41");
1482                 }
1483                 {
1484                         bool errorThrown = false;
1485                         try {
1486                                 char[,] c = new Char[2,2];
1487                                 Array.LastIndexOf(c, "huh?", 0, 1);
1488                         } catch (RankException) {
1489                                 errorThrown = true;
1490                         }
1491                         Assert.IsTrue (errorThrown, "#K42");
1492                 }
1493                 {
1494                         bool errorThrown = false;
1495                         try {
1496                                 char[] c = new Char[2];
1497                                 Array.LastIndexOf(c, "huh?", 3, 1);
1498                         } catch (ArgumentOutOfRangeException) {
1499                                 errorThrown = true;
1500                         }
1501                         Assert.IsTrue (errorThrown, "#K43");
1502                 }
1503                 {
1504                         bool errorThrown = false;
1505                         try {
1506                                 char[] c = new Char[2];
1507                                 Array.LastIndexOf(c, "huh?", 0, 5);
1508                         } catch (ArgumentOutOfRangeException) {
1509                                 errorThrown = true;
1510                         }
1511                         Assert.IsTrue (errorThrown, "#K44");
1512                 }
1513
1514                 String[] s1 = {"this", "is", "really", "a", "test"};
1515                 Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3, 3), "#K45");
1516                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3, 3), "#K46");
1517                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "this", 3, 3), "#K47");
1518                 Assert.AreEqual (1, Array.LastIndexOf(s1, "is", 3, 3), "#K48");
1519                 Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3, 3), "#K49");
1520                 Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3, 3), "#K50");
1521         }
1522
1523         [Test]
1524         public void TestLastIndexOf4 ()
1525         {
1526                 short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
1527                 try {
1528                         Array.LastIndexOf (a, (object)16, -1);
1529                         NUnit.Framework.Assert.Fail ("#1");
1530                 } catch (ArgumentOutOfRangeException) { }
1531                 
1532 #if NET_2_0             
1533                 try {
1534                         Array.LastIndexOf<short> (a, 16, -1);
1535                         NUnit.Framework.Assert.Fail ("#2");
1536                 } catch (ArgumentOutOfRangeException) { }
1537 #endif          
1538         }
1539
1540         [Test]
1541         public void TestLastIndexOf5 ()
1542         {
1543                 char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
1544                 string s;
1545                 int retval;
1546                 bool error = false;
1547
1548                 for (int i = a.Length - 1; i >= 0 ; i--) {
1549                         s = i.ToString ();
1550                         retval = Array.LastIndexOf(a, a [i], i, i + 1);
1551                         if (retval != i)
1552                                 error = true;
1553                 }
1554                 Assert.IsTrue (!error);
1555         }
1556
1557         [Test]
1558         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1559         public void LastIndexOf_StartIndexOverflow ()
1560         {
1561                 // legal - no exception
1562                 byte[] array = new byte [16];
1563                 Array.LastIndexOf (array, this, Int32.MaxValue, 1);
1564         }
1565
1566         [Test]
1567         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1568         public void LastIndexOf_CountOverflow ()
1569         {
1570                 // legal - no exception
1571                 byte[] array = new byte [16];
1572                 Array.LastIndexOf (array, this, 1, Int32.MaxValue);
1573         }
1574
1575         [Test]
1576         public void LastIndexOf_0LengthArray ()
1577         {
1578                 Array array = Array.CreateInstance (typeof (char), 0);
1579                 int idx = Array.LastIndexOf (array, (object) null, -1, 0);
1580                 Assert.IsTrue (idx == -1, "#01");
1581                 idx = Array.LastIndexOf (array, (object) null, -1, 10);
1582                 Assert.IsTrue (idx == -1, "#02");
1583                 idx = Array.LastIndexOf (array, (object) null, -100, 10);
1584                 Assert.IsTrue (idx == -1, "#02");
1585
1586                 array = Array.CreateInstance (typeof (char), 1);
1587                 try {
1588                         Array.LastIndexOf (array, (object) null, -1, 0);
1589                         Assert.Fail ("#04");
1590                 } catch (ArgumentOutOfRangeException e) {
1591                 }
1592                 try {
1593                         Array.LastIndexOf (array, (object) null, -1, 10);
1594                         Assert.Fail ("#05");
1595                 } catch (ArgumentOutOfRangeException e) {
1596                 }
1597                 try {
1598                         Array.LastIndexOf (array, (object) null, -100, 10);
1599                         Assert.Fail ("#06");
1600                 } catch (ArgumentOutOfRangeException e) {
1601                 }
1602         }
1603
1604         [Test]
1605         public void TestReverse() {
1606                 {
1607                         bool errorThrown = false;
1608                         try {
1609                                 Array.Reverse(null);
1610                         } catch (ArgumentNullException) {
1611                                 errorThrown = true;
1612                         }
1613                         Assert.IsTrue (errorThrown, "#L01");
1614                 }
1615                 {
1616                         bool errorThrown = false;
1617                         try {
1618                                 char[,] c = new Char[2,2];
1619                                 Array.Reverse(c);
1620                         } catch (RankException) {
1621                                 errorThrown = true;
1622                         }
1623                         Assert.IsTrue (errorThrown, "#L02");
1624                 }
1625                 
1626                 char[] c1 = {'a', 'b', 'c', 'd'};
1627                 Array.Reverse(c1);
1628                 Assert.AreEqual ('d', c1[0], "#L03");
1629                 Assert.AreEqual ('c', c1[1], "#L04");
1630                 Assert.AreEqual ('b', c1[2], "#L05");
1631                 Assert.AreEqual ('a', c1[3], "#L06");
1632
1633                 {
1634                         bool errorThrown = false;
1635                         try {
1636                                 Array.Reverse(null, 0, 0);
1637                         } catch (ArgumentNullException) {
1638                                 errorThrown = true;
1639                         }
1640                         Assert.IsTrue (errorThrown, "#L07");
1641                 }
1642                 {
1643                         bool errorThrown = false;
1644                         try {
1645                                 char[,] c = new Char[2,2];
1646                                 Array.Reverse(c, 0, 0);
1647                         } catch (RankException) {
1648                                 errorThrown = true;
1649                         }
1650                         Assert.IsTrue (errorThrown, "#L08");
1651                 }
1652                 //{
1653                 //bool errorThrown = false;
1654                 //try {
1655                 //      char[] c = new Char[2];
1656                 //      Array.Reverse(c, 0, 3);
1657                 //} catch (ArgumentOutOfRangeException) {
1658                 //      errorThrown = true;
1659                 //}
1660                 //Assert.IsTrue (errorThrown, "#L09");
1661                 //}
1662                 //{
1663                 //bool errorThrown = false;
1664                 //try {
1665                 //      char[] c = new Char[2];
1666                 //      Array.Reverse(c, 3, 0);
1667                 //} catch (ArgumentOutOfRangeException) {
1668                 //      errorThrown = true;
1669                 //}
1670                 //Assert.IsTrue (errorThrown, "#L10");
1671                 //}
1672
1673                 char[] c2 = { 'a', 'b', 'c', 'd'};
1674                 Array.Reverse(c2, 1, 2);
1675                 Assert.AreEqual ('a', c2[0], "#L11");
1676                 Assert.AreEqual ('c', c2[1], "#L12");
1677                 Assert.AreEqual ('b', c2[2], "#L13");
1678                 Assert.AreEqual ('d', c2[3], "#L14");
1679         }
1680
1681         [Test]
1682         public void TestSetValue1() {
1683                 {
1684                         bool errorThrown = false;
1685                         try {
1686                                 char[,] c = new Char[2,2];
1687                                 c.SetValue("buh", 1);
1688                         } catch (ArgumentException) {
1689                                 errorThrown = true;
1690                         }
1691                         Assert.IsTrue (errorThrown, "#M01");
1692                 }
1693                 {
1694                         bool errorThrown = false;
1695                         try {
1696                                 char[] c = {'a', 'b', 'c'};
1697                                 c.SetValue("buh", -1);
1698                         } catch (IndexOutOfRangeException) {
1699                                 errorThrown = true;
1700                         }
1701                         Assert.IsTrue (errorThrown, "#M02");
1702                 }
1703                 {
1704                         bool errorThrown = false;
1705                         try {
1706                                 char[] c = {'a', 'b', 'c'};
1707                                 c.SetValue("buh", 4);
1708                         } catch (IndexOutOfRangeException) {
1709                                 errorThrown = true;
1710                         }
1711                         Assert.IsTrue (errorThrown, "#M03");
1712                 }
1713
1714                 char[] c1 = {'a', 'b', 'c', 'd'};
1715                 char[] c2 = new char[4];
1716                 for (int i = 0; i < c1.Length; i++) {
1717                         c2.SetValue(c1[i], i);
1718                 }
1719                 for (int i = 0; i < c1.Length; i++) {
1720                         Assert.AreEqual (c1[i], c2[i], "#M04(" + i + ")");
1721                 }
1722
1723                 int[] c3 = { 1, 2, 3 };
1724                 long[] c4 = new long [3];
1725
1726                 for (int i = 0; i < c3.Length; i++)
1727                         c4.SetValue (c3 [i], i);
1728
1729                 try {
1730                         c3.CopyTo (c4, 0);
1731                 } catch (Exception e) {
1732                         Assert.Fail ("c3.CopyTo(): e=" + e);
1733                 }
1734                 for (int i = 0; i < c3.Length; i++)
1735                         Assert.IsTrue (c3[i] == c4[i], "#M05(" + i + ")");
1736
1737                 Object[] c5 = new Object [3];
1738                 long[] c6 = new long [3];
1739
1740                 try {
1741                         c4.CopyTo (c5, 0);
1742                 } catch (Exception e) {
1743                         Assert.Fail ("c4.CopyTo(): e=" + e);
1744                 }
1745
1746                 try {
1747                         c5.CopyTo (c6, 0);
1748                 } catch (Exception e) {
1749                         Assert.Fail ("c5.CopyTo(): e=" + e);
1750                 }
1751                 // for (int i = 0; i < c5.Length; i++)
1752                 // Assert.IsTrue (c5[i] == c6[i], "#M06(" + i + ")");
1753         }
1754
1755         [Test]
1756         public void TestSetValue2() {
1757                 {
1758                         bool errorThrown = false;
1759                         try {
1760                                 char[] c = new Char[2];
1761                                 c.SetValue("buh", 1,1);
1762                         } catch (ArgumentException) {
1763                                 errorThrown = true;
1764                         }
1765                         Assert.IsTrue (errorThrown, "#M21");
1766                 }
1767                 {
1768                         bool errorThrown = false;
1769                         try {
1770                                 char[,] c = new Char[2,2];
1771                                 c.SetValue("buh", -1, 1);
1772                         } catch (IndexOutOfRangeException) {
1773                                 errorThrown = true;
1774                         }
1775                         Assert.IsTrue (errorThrown, "#M22");
1776                 }
1777                 {
1778                         bool errorThrown = false;
1779                         try {
1780                                 char[,] c = new Char[2,2];
1781                                 c.SetValue("buh", 4,1);
1782                         } catch (IndexOutOfRangeException) {
1783                                 errorThrown = true;
1784                         }
1785                         Assert.IsTrue (errorThrown, "#M23");
1786                 }
1787
1788                 char[,] c1 = new Char[4,6];
1789                 char[,] c2 = new Char[4,6];
1790                 for (int i = 0; i < 24; i++) {
1791                         int first = i / 6;
1792                         int second = i % 6;
1793                         c1[first,second] = (char)(((int)'a')+i);
1794                         c2.SetValue(c1[first,second], first, second);
1795                 }
1796                 for (int i = 0; i < c1.GetLength(0); i++) {
1797                         for (int j = 0; j < c1.GetLength(1); j++) {
1798                                 Assert.AreEqual (c1[i, j], c2[i, j], "#M24(" + i + "," + j + ")");
1799                         }
1800                 }
1801         }
1802
1803         [Test]
1804         public void TestSetValue3() {
1805                 {
1806                         bool errorThrown = false;
1807                         try {
1808                                 char[] c = new Char[2];
1809                                 c.SetValue("buh", 1,1,1);
1810                         } catch (ArgumentException) {
1811                                 errorThrown = true;
1812                         }
1813                         Assert.IsTrue (errorThrown, "#M41");
1814                 }
1815                 {
1816                         bool errorThrown = false;
1817                         try {
1818                                 char[,,] c = new Char[2,2,2];
1819                                 c.SetValue("buh", -1, 1, 1);
1820                         } catch (IndexOutOfRangeException) {
1821                                 errorThrown = true;
1822                         }
1823                         Assert.IsTrue (errorThrown, "#M42");
1824                 }
1825                 {
1826                         bool errorThrown = false;
1827                         try {
1828                                 char[,,] c = new Char[2,2,2];
1829                                 c.SetValue("buh", 4,1,1);
1830                         } catch (IndexOutOfRangeException) {
1831                                 errorThrown = true;
1832                         }
1833                         Assert.IsTrue (errorThrown, "#M43");
1834                 }
1835
1836                 char[,,] c1 = new Char[4,2,3];
1837                 char[,,] c2 = new Char[4,2,3];
1838                 for (int i = 0; i < 24; i++) {
1839                         int first = i / 6;
1840                         int remains = i % 6;
1841                         int second = remains / 3;
1842                         int third = remains % 3;
1843                         c1[first,second, third] = (char)(((int)'a')+i);
1844                         c2.SetValue(c1[first, second, third], first, second, third);
1845                 }
1846                 for (int i = 0; i < c1.GetLength(0); i++) {
1847                         for (int j = 0; j < c1.GetLength(1); j++) {
1848                                 for (int k = 0; k < c1.GetLength(2); k++) {
1849                                         Assert.AreEqual (c1[i, j, k], c2[i, j, k], "#M44(" + i + "," + j + " )");
1850                                 }
1851                         }
1852                 }
1853         }
1854
1855         [Test]
1856 #if NET_2_0
1857         [ExpectedException (typeof (ArgumentNullException))]
1858 #else
1859         [ExpectedException (typeof (NullReferenceException))]
1860 #endif
1861         public void TestSetValueLongArray ()
1862         {
1863                 char[] c = new Char[2];
1864                 c.SetValue("buh", (long [])null);
1865         }
1866
1867         [Test]
1868         public void TestSetValueN() {
1869                 {
1870                         bool errorThrown = false;
1871                         try {
1872                                 char[] c = new Char[2];
1873                                 c.SetValue("buh", (int [])null);
1874                         } catch (ArgumentNullException) {
1875                                 errorThrown = true;
1876                         }
1877                         Assert.IsTrue (errorThrown, "#M61a");
1878                 }
1879                 {
1880                         bool errorThrown = false;
1881                         try {
1882                                 char[] c = new Char[2];
1883                                 int[] coords = {1, 1};
1884                                 c.SetValue("buh", coords);
1885                         } catch (ArgumentException) {
1886                                 errorThrown = true;
1887                         }
1888                         Assert.IsTrue (errorThrown, "#M62");
1889                 }
1890                 {
1891                         bool errorThrown = false;
1892                         try {
1893                                 char[,] c = new Char[2,2];
1894                                 int[] coords = {-1, 1};
1895                                 c.SetValue("buh", coords);
1896                         } catch (IndexOutOfRangeException) {
1897                                 errorThrown = true;
1898                         }
1899                         Assert.IsTrue (errorThrown, "#M63");
1900                 }
1901                 {
1902                         bool errorThrown = false;
1903                         try {
1904                                 char[,] c = new Char[2,2];
1905                                 int[] coords = {4, 1};
1906                                 c.SetValue("buh", coords);
1907                         } catch (IndexOutOfRangeException) {
1908                                 errorThrown = true;
1909                         }
1910                         Assert.IsTrue (errorThrown, "#M64");
1911                 }
1912
1913                 char[,] c1 = new Char[4,6];
1914                 char[,] c2 = new Char[4,6];
1915                 for (int i = 0; i < 24; i++) {
1916                         int first = i / 6;
1917                         int second = i % 6;
1918                         c1[first,second] = (char)(((int)'a')+i);
1919                         int[] coords = {first, second};
1920                         c2.SetValue(c1[first,second], coords);
1921                 }
1922                 for (int i = 0; i < c1.GetLength(0); i++) {
1923                         for (int j = 0; j < c1.GetLength(1); j++) {
1924                                 Assert.AreEqual (c1[i, j], c2[i, j], "#M65(" + i + "," + j + ")");
1925                         }
1926                 }
1927         }
1928
1929         [Test]
1930         public void TestSetValue4() {
1931                 {
1932                         int[] c1 = { 1, 2, 3 };
1933                         long[] c2 = new long [3];
1934
1935                         for (int i = 0; i < c1.Length; i++)
1936                                 c2.SetValue (c1 [i], i);
1937
1938                         for (int i = 0; i < c1.Length; i++) {
1939                                 Assert.IsTrue (c1[i] == c2[i], "#M81(" + i + ")");
1940                                 Assert.AreEqual (typeof (long), c2[i].GetType (), "#M82(" + i + ")");
1941                         }
1942                 }
1943                 {
1944                         long[] c1 = { 1, 2, 3 };
1945                         int[] c2 = new int [3];
1946                         bool errorThrown = false;
1947                         try {
1948                                 c2.SetValue (c1 [0], 0);
1949                         } catch (ArgumentException) {
1950                                 errorThrown = true;
1951                         }
1952                         Assert.IsTrue (errorThrown, "#M83");
1953                 }
1954                 {
1955                         int[] c1 = { 1, 2, 3 };
1956                         Object[] c2 = new Object [3];
1957
1958                         for (int i = 0; i < c1.Length; i++)
1959                                 c2.SetValue (c1 [i], i);
1960
1961                         for (int i = 0; i < c1.Length; i++)
1962                                 Assert.AreEqual (c1[i], Convert.ToInt32 (c2[i]), "#M84(" + i + ")");
1963                 }
1964                 {
1965                         Object[] c1 = new Object [3];
1966                         Object[] c2 = new Object [3];
1967                         c1[0] = new Object ();
1968
1969                         for (int i = 0; i < c1.Length; i++)
1970                                 c2.SetValue (c1 [i], i);
1971
1972                         for (int i = 0; i < c1.Length; i++)
1973                                 Assert.AreEqual (c1[i], c2[i], "#M85(" + i + ")");
1974                 }
1975                 {
1976                         Object[] c1 = new Object [3];
1977                         string[] c2 = new String [3];
1978                         string test = "hello";
1979                         c1[0] = test;
1980
1981                         c2.SetValue (c1 [0], 0);
1982                         Assert.AreEqual (c1[0], c2[0], "#M86");
1983                         Assert.AreEqual ("hello", c2[0], "#M87");
1984                 }
1985                 {
1986                         char[] c1 = { 'a', 'b', 'c' };
1987                         string[] c2 = new string [3];
1988                         try {
1989                                 c2.SetValue (c1 [0], 0);
1990                                 Assert.Fail ("#M88");
1991                         } catch (InvalidCastException) {}
1992                 }
1993                 {
1994                         Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
1995                         long[] c2 = new long [3];
1996                         try {
1997                                 c2.SetValue (c1 [0], 0);
1998                                 Assert.Fail ("#M89");
1999                         } catch (ArgumentException) {}
2000                 }
2001                 {
2002                         Type[] types = {
2003                                 typeof (Boolean),
2004                                 typeof (Byte),
2005                                 typeof (Char),
2006                                 typeof (Double),
2007                                 typeof (Int16),
2008                                 typeof (Int32),
2009                                 typeof (Int64),
2010                                 typeof (SByte),
2011                                 typeof (Single),
2012                                 typeof (UInt16),
2013                                 typeof (UInt32),
2014                                 typeof (UInt64)
2015                         };
2016
2017                         bool v1 = true;
2018                         Byte v2 = 1;
2019                         Char v3 = 'a';
2020                         Double v4 = -1.2;
2021                         Int16 v5 = -32;
2022                         Int32 v6 = -234;
2023                         Int64 v7 = -34523;
2024                         SByte v8 = -1;
2025                         Single v9 = -4.8F;
2026                         UInt16 v10 = 24234;
2027                         UInt32 v11 = 235354;
2028                         UInt64 v12 = 234552;
2029
2030                         Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
2031                         Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
2032                                          "-4.8F", "24234", "235354", "234552" };
2033
2034                         Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
2035
2036                         int[] arg_ex = {
2037                                 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2038                                 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
2039                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
2040                                 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
2041                                 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
2042                                 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
2043                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
2044                                 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
2045                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
2046                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
2047                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
2048                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
2049                         };
2050
2051                         // SetValue
2052
2053                         for (int i = 0; i < types.Length; i++) {
2054                                 for (int j = 0; j < types.Length; j++) {
2055                                         Array array = Array.CreateInstance (types [j], 2);
2056
2057                                         Object value = vt[j][i];
2058
2059                                         bool errorThrown = false;
2060                                         try {
2061                                                 array.SetValue (value, 0);
2062                                         } catch (ArgumentException) {
2063                                                 errorThrown = true;
2064                                         }
2065
2066                                         int ex_index = (i * types.Length) + j;
2067
2068                                         Assert.AreEqual (errorThrown, arg_ex [ex_index] == 1, "#M90(" + types [i] + "," + types [j] + ")");
2069                                 }
2070                         }
2071
2072                         for (int i = 0; i < types.Length; i++) {
2073                                 String[] array = new String [2];
2074
2075                                 Object value = va1 [i];
2076
2077                                 bool errorThrown = false;
2078                                 try {
2079                                         array.SetValue (value, 0);
2080                                 } catch (InvalidCastException) {
2081                                         errorThrown = true;
2082                                 }
2083
2084                                 Assert.IsTrue (errorThrown, "#M91(" + types [i] + ")");
2085                         }
2086
2087                         for (int i = 0; i < types.Length; i++) {
2088                                 Array array = Array.CreateInstance (types [i], 2);
2089
2090                                 Object value = va2 [i];
2091
2092                                 bool errorThrown = false;
2093                                 try {
2094                                         array.SetValue (value, 0);
2095                                 } catch (InvalidCastException) {
2096                                         errorThrown = true;
2097                                 }
2098
2099                                 Assert.IsTrue (errorThrown, "#M92(" + types [i] + ")");
2100                         }
2101
2102                         for (int i = 0; i < types.Length; i++) {
2103                                 Array array = Array.CreateInstance (types [i], 2);
2104
2105                                 Object value = null;
2106
2107                                 bool errorThrown = false;
2108                                 try {
2109                                         array.SetValue (value, 0);
2110                                 } catch (InvalidCastException) {
2111                                         errorThrown = true;
2112                                 }
2113
2114                                 Assert.IsTrue (!errorThrown, "#M93(" + types [i] + ")");
2115                         }
2116
2117                         // Copy
2118
2119                         for (int i = 0; i < types.Length; i++) {
2120                                 for (int j = 0; j < types.Length; j++) {
2121                                         Array source = Array.CreateInstance (types [i], 2);
2122                                         Array array = Array.CreateInstance (types [j], 2);
2123
2124                                         source.SetValue (vt[j][i], 0);
2125                                         source.SetValue (vt[j][i], 1);
2126
2127                                         bool errorThrown = false;
2128                                         try {
2129                                                 Array.Copy (source, array, 2);
2130                                         } catch (ArrayTypeMismatchException) {
2131                                                 errorThrown = true;
2132                                         }
2133
2134                                         int ex_index = (i * types.Length) + j;
2135
2136                                         Assert.AreEqual (errorThrown, arg_ex [ex_index] == 1, "#M94(" + types [i] + "," + types [j] + ")");
2137                                 }
2138                         }
2139
2140                         for (int i = 0; i < types.Length; i++) {
2141                                 Array source = Array.CreateInstance (types [i], 2);
2142                                 String[] array = new String [2];
2143
2144                                 source.SetValue (va1 [i], 0);
2145                                 source.SetValue (va1 [i], 1);
2146
2147                                 bool errorThrown = false;
2148                                 try {
2149                                         Array.Copy (source, array, 2);
2150                                 } catch (ArrayTypeMismatchException) {
2151                                         errorThrown = true;
2152                                 }
2153
2154                                 Assert.IsTrue (errorThrown, "#M95(" + types [i] + ")");
2155                         }
2156
2157                         for (int i = 0; i < types.Length; i++) {
2158                                 String[] source = new String [2];
2159                                 Array array = Array.CreateInstance (types [i], 2);
2160
2161                                 source.SetValue (va2 [i], 0);
2162                                 source.SetValue (va2 [i], 1);
2163
2164                                 bool errorThrown = false;
2165                                 try {
2166                                         Array.Copy (source, array, 2);
2167                                 } catch (ArrayTypeMismatchException) {
2168                                         errorThrown = true;
2169                                 }
2170
2171                                 Assert.IsTrue (errorThrown, "#M96(" + types [i] + ")");
2172                         }
2173                 }
2174         }
2175
2176         [Test]
2177         public void TestSort() {
2178                 {
2179                         bool errorThrown = false;
2180                         try {
2181                                 Array.Sort(null);
2182                         } catch (ArgumentNullException) {
2183                                 errorThrown = true;
2184                         }
2185                         Assert.IsTrue (errorThrown, "#N01");
2186                 }
2187                 {
2188                         bool errorThrown = false;
2189                         try {
2190                                 Array.Sort(null, 0, 1);
2191                         } catch (ArgumentNullException) {
2192                                 errorThrown = true;
2193                         }
2194                         Assert.IsTrue (errorThrown, "#N02");
2195                 }
2196                 {
2197                         bool errorThrown = false;
2198                         try {
2199                                 char[] c1 = new Char[2];
2200                                 Array.Sort(null, c1);
2201                         } catch (ArgumentNullException) {
2202                                 errorThrown = true;
2203                         }
2204                         Assert.IsTrue (errorThrown, "#N03");
2205                 }
2206                 {
2207                         bool errorThrown = false;
2208                         try {
2209                                 char[] c1 = new Char[2];
2210                                 Array.Sort(null, c1, 0, 1);
2211                         } catch (ArgumentNullException) {
2212                                 errorThrown = true;
2213                         }
2214                         Assert.IsTrue (errorThrown, "#N04");
2215                 }
2216                 {
2217                         int tc = 5;
2218                         char[] arr = {'d', 'b', 'f', 'e', 'a', 'c'};
2219                         
2220                         try {
2221                                 Array.Sort (null, 0, 1);
2222                                 Assert.Fail ("#N" + tc.ToString ());
2223                         }
2224                         catch (ArgumentException) {}
2225                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2226                         tc++;
2227                         
2228                         try {
2229                                 Array.Sort (arr, -1, 3);
2230                                 Assert.Fail ("#N" + tc.ToString ());
2231                         }
2232                         catch (ArgumentException) {}
2233                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2234                         tc++;
2235                         
2236                         try {
2237                                 Array.Sort (arr, 1, -3);
2238                                 Assert.Fail ("#N" + tc.ToString ());
2239                         }
2240                         catch (ArgumentException) {}
2241                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2242                         tc++;
2243                         
2244                         try {
2245                                 Array.Sort (arr, arr.Length, arr.Length + 2);
2246                                 Assert.Fail ("#N" + tc.ToString ());
2247                         }
2248                         catch (ArgumentException) {}
2249                         catch (Exception) { Assert.Fail ("#N" + tc.ToString ()); }
2250                 }
2251                 
2252                 // note: null second array => just sort first array
2253                 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
2254                 int[] starter1 = {1,2,3,4,5,6};
2255                 {
2256                         char[] c1 = (char[])starter.Clone();
2257                         Array.Sort(c1);
2258                         Assert.AreEqual ('a', c1[0], "#N21");
2259                         Assert.AreEqual ('b', c1[1], "#N22");
2260                         Assert.AreEqual ('c', c1[2], "#N23");
2261                         Assert.AreEqual ('d', c1[3], "#N24");
2262                         Assert.AreEqual ('e', c1[4], "#N25");
2263                         Assert.AreEqual ('f', c1[5], "#N26");
2264                 }
2265                 {
2266                         char[] c1 = (char[])starter.Clone();
2267                         int[] i1 = (int[])starter1.Clone();
2268                         Array.Sort(c1, i1);
2269                         Assert.AreEqual ('a', c1[0], "#N41");
2270                         Assert.AreEqual ('b', c1[1], "#N42");
2271                         Assert.AreEqual ('c', c1[2], "#N43");
2272                         Assert.AreEqual ('d', c1[3], "#N44");
2273                         Assert.AreEqual ('e', c1[4], "#N45");
2274                         Assert.AreEqual ('f', c1[5], "#N46");
2275                         Assert.AreEqual (5, i1[0], "#N47");
2276                         Assert.AreEqual (2, i1[1], "#N48");
2277                         Assert.AreEqual (6, i1[2], "#N49");
2278                         Assert.AreEqual (1, i1[3], "#N50");
2279                         Assert.AreEqual (4, i1[4], "#N51");
2280                         Assert.AreEqual (3, i1[5], "#N52");
2281                 }
2282                 {
2283                         char[] c1 = (char[])starter.Clone();
2284                         Array.Sort(c1, 1, 4);
2285                         Assert.AreEqual ('d', c1[0], "#N61");
2286                         Assert.AreEqual ('a', c1[1], "#N62");
2287                         Assert.AreEqual ('b', c1[2], "#N63");
2288                         Assert.AreEqual ('e', c1[3], "#N64");
2289                         Assert.AreEqual ('f', c1[4], "#N65");
2290                         Assert.AreEqual ('c', c1[5], "#N66");
2291                 }
2292                 {
2293                         char[] c1 = (char[])starter.Clone();
2294                         int[] i1 = (int[])starter1.Clone();
2295                         Array.Sort(c1, i1, 1, 4);
2296                         Assert.AreEqual ('d', c1[0], "#N81");
2297                         Assert.AreEqual ('a', c1[1], "#N82");
2298                         Assert.AreEqual ('b', c1[2], "#N83");
2299                         Assert.AreEqual ('e', c1[3], "#N84");
2300                         Assert.AreEqual ('f', c1[4], "#N85");
2301                         Assert.AreEqual ('c', c1[5], "#N86");
2302                         Assert.AreEqual (1, i1[0], "#N87");
2303                         Assert.AreEqual (5, i1[1], "#N88");
2304                         Assert.AreEqual (2, i1[2], "#N89");
2305                         Assert.AreEqual (4, i1[3], "#N90");
2306                         Assert.AreEqual (3, i1[4], "#N91");
2307                         Assert.AreEqual (6, i1[5], "#N92");
2308                 }
2309         }
2310
2311         [Test]
2312         public void TestInitializeEmpty()
2313         {
2314                 bool catched=false;
2315                 int[] a = {};
2316                 try
2317                 {
2318                         a.Initialize();
2319                 }
2320                 catch(Exception)
2321                 {
2322                         catched=true;
2323                 }
2324                 Assert.IsTrue (!catched, "#TI01");
2325         }
2326
2327         [Test]
2328         public void TestInitializeInt()
2329         {
2330                 int[] a = {1,2,0};
2331                 a.Initialize();
2332                 int[] b = {1,2,0};
2333                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2334                 {
2335                         Assert.AreEqual (a[i], b[i], "#TI02 " + i);
2336                 }
2337         }
2338
2339         [Test]
2340         public void TestInitializeDouble()
2341         {
2342                 double[] a = {1.0,2.0,0.0};
2343                 a.Initialize();
2344                 double[] b = {1.0,2.0,0.0};
2345                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2346                 {
2347                         Assert.AreEqual (a[i], b[i], "#TI03 " + i);
2348                 }
2349         }
2350
2351         [Test]
2352         public void TestInitializeFloat()
2353         {
2354                 float[] a = {1.0F,2.0F,0.0F};
2355                 a.Initialize();
2356                 float[] b = {1.0F,2.0F,0.0F};
2357                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2358                 {
2359                         Assert.AreEqual (a[i], b[i], "#TI04 " + i);
2360                 }
2361         }
2362
2363         [Test]
2364         public void TestInitializeChar()
2365         {
2366                 char[] a = {'1','.','0','F','2','.','0','F'};
2367                 a.Initialize();
2368                 char[] b = {'1','.','0','F','2','.','0','F'};
2369                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2370                 {
2371                         Assert.AreEqual (a[i], b[i], "#TI05 " + i);
2372                 }
2373         }
2374
2375         [Test]
2376         public void TestInitializeString()
2377         {
2378                 string[] a = {"hola","adios","menos","mas"};
2379                 a.Initialize();
2380                 string[] b = {"hola","adios","menos","mas"};
2381                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2382                 {
2383                         Assert.AreEqual (a[i], b[i], "#TI06 " + i);
2384                 }
2385         }
2386
2387         [Test]
2388         public void TestInitializeEnum()
2389         {
2390                 enua[] a = {enua.hola,enua.adios,enua.menos,enua.mas};
2391                 a.Initialize();
2392                 enua[] b = {enua.hola,enua.adios,enua.menos,enua.mas};
2393                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2394                 {
2395                         Assert.AreEqual (a[i], b[i], "#TI07 " + i);
2396                 }
2397         }
2398         
2399         [Test]
2400         public void TestInitializeIntNI()
2401         {
2402                 int[] a = new int[20];
2403                 a.Initialize();
2404                 foreach(int b in a)
2405                 {
2406                         Assert.AreEqual (b, 0, "#TI08");
2407                 }
2408         }
2409         
2410         [Test]
2411         public void TestInitializeCharNI()
2412         {
2413                 char[] a = new char[20];
2414                 a.Initialize();
2415                 foreach(char b in a)
2416                 {
2417                         Assert.AreEqual (b, 0, "#TI09");
2418                 }
2419         }
2420         
2421         [Test]
2422         public void TestInitializeDoubleNI()
2423         {
2424                 double[] a = new double[20];
2425                 a.Initialize();
2426                 foreach(double b in a)
2427                 {
2428                         Assert.AreEqual (b, 0.0, "#TI09");
2429                 }
2430         }
2431         
2432         [Test]
2433         public void TestInitializeStringNI()
2434         {
2435                 string[] a = new string[20];
2436                 a.Initialize();
2437                 foreach(string b in a)
2438                 {
2439                         Assert.AreEqual (b, null, "#TI10");
2440                 }
2441         }
2442         
2443         [Test]
2444         public void TestInitializeObjectNI()
2445         {
2446                 object[] a = new object[20];
2447                 a.Initialize();
2448                 foreach(object b in a)
2449                 {
2450                         Assert.AreEqual (b, null, "#TI11");
2451                 }
2452         }
2453
2454         [Test]
2455         public void TestInitializeAClassNI()
2456         {
2457                 AClass[] a = new AClass[20];
2458                 a.Initialize();
2459                 foreach(AClass b in a)
2460                 {
2461                         Assert.AreEqual (b, null, "#TI12");
2462                 }
2463         }
2464
2465
2466         [Test]
2467         public void TestInitializeAStructNI()
2468         {
2469                 AStruct[] a = new AStruct[20];
2470                 a.Initialize();
2471                 foreach(AStruct b in a)
2472                 {
2473                         Assert.AreEqual (b, new AStruct(), "#TI14");
2474                 }
2475         }
2476
2477         [Test]
2478         public void TestInitializeAStruct()
2479         {
2480                 AStruct[] a = new AStruct[3];
2481                 a[1].a = "ADIOS";
2482                 a[1].s = "HOLA";
2483                 a.Initialize();
2484                 AStruct[] b = new AStruct[3];
2485                 b[1].a = "ADIOS";
2486                 b[1].s = "HOLA";
2487                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2488                 {
2489                         Assert.AreEqual (a[i], b[i], "#TI15 " + i);
2490                 }
2491         }
2492
2493         [Test]
2494         public void TestInitializeDateTimeNI()
2495         {
2496                 DateTime[] a = new DateTime[20];
2497                 a.Initialize();
2498                 foreach(DateTime b in a)
2499                 {
2500                         Assert.AreEqual (b, new DateTime(), "#TI16");
2501                 }
2502         }
2503         
2504         [Test]
2505         [ExpectedException (typeof (ArgumentNullException))]
2506         public void MoreSort1 ()
2507         {
2508                 Array.Sort (null, 0, 1);
2509         }
2510
2511         [Test]
2512         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2513         public void MoreSort2 ()
2514         {
2515                 Array.Sort (arrsort, -1, 3);
2516         }
2517
2518         [Test]
2519         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2520         public void MoreSort3 ()
2521         {
2522                 Array.Sort (arrsort, 1, -3);
2523         }
2524
2525         [Test]
2526         [ExpectedException (typeof (ArgumentException))]
2527         public void MoreSort4 ()
2528         {
2529                 Array.Sort (arrsort, arrsort.Length, arrsort.Length + 2);
2530         }
2531
2532         [Test]
2533         [ExpectedException (typeof (RankException))]
2534         public void MoreSort5 ()
2535         {
2536                 char [,] arr = new char [,] {{'a'}, {'b'}};
2537                 Array.Sort (arr, 0, 1);
2538         }
2539
2540         [Test]
2541         public void MoreSort6 ()
2542         {
2543                 Array.Sort (arrsort, 0, 0);
2544         }
2545
2546         [Test]
2547         [ExpectedException (typeof (ArgumentException))]
2548         public void MoreSort7 ()
2549         {
2550                 Array.Sort (arrsort, arrsort.Length - 1, 2);
2551         }
2552
2553         [Test]
2554         [ExpectedException (typeof (ArgumentException))]
2555         public void MoreSort8 ()
2556         {
2557                 Array.Sort (arrsort, 0, arrsort.Length + 1);
2558         }
2559
2560         [Test]
2561         public void MoreSort9 ()
2562         {
2563                 Array.Sort (arrsort, null, 0, arrsort.Length, null);
2564         }
2565
2566         [Test]
2567         [ExpectedException (typeof (InvalidOperationException))]
2568         public void MoreSort10 ()
2569         {
2570                 object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
2571                 Array.Sort (array, (IComparer) null);
2572         }
2573
2574         [Test] // bug #81941
2575         public void Sort ()
2576         {
2577                 double [] a = new double [2] { 0.9, 0.3 };
2578                 uint [] b = new uint [2] { 4, 7 };
2579                 Array.Sort (a, b);
2580                 Assert.AreEqual (0.3, a [0], "#1");
2581                 Assert.AreEqual (0.9, a [1], "#2");
2582                 Assert.AreEqual (7, b [0], "#3");
2583                 Assert.AreEqual (4, b [1], "#4");
2584         }
2585
2586         [Test]
2587         public void ClearJaggedArray () 
2588         {
2589                 byte[][] matrix = new byte [8][];
2590                 for (int i=0; i < 8; i++) {
2591                         matrix [i] = new byte [8];
2592                         for (int j=0; j < 8; j++) {
2593                                 matrix [i][j] = 1;
2594                         }
2595                 }
2596                 Array.Clear (matrix, 0, 8);
2597                 for (int i=0; i < 8; i++) {
2598                         Assert.IsNull (matrix [i], i.ToString ());
2599                 }
2600         }
2601
2602         [Test]
2603         public void ClearMultidimentionalArray () 
2604         {
2605                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2606                 Array.Clear (matrix, 0, 2);
2607                 Assert.AreEqual (0, matrix [0, 0], "0,0");
2608                 Assert.AreEqual (0, matrix [0, 1], "0,1");
2609                 Assert.AreEqual (2, matrix [1, 0], "1,0");
2610                 Assert.AreEqual (2, matrix [1, 1], "1,1");
2611         }
2612
2613         [Test]
2614         [ExpectedException (typeof (IndexOutOfRangeException))]
2615         public void ClearOutsideMultidimentionalArray () 
2616         {
2617                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2618                 Array.Clear (matrix, 0, 5);
2619         }
2620
2621         [Test]
2622         [ExpectedException (typeof (IndexOutOfRangeException))]
2623         public void Clear_IndexOverflow () 
2624         {
2625                 byte[] array = new byte [16];
2626                 Array.Clear (array, 4, Int32.MaxValue);
2627         }
2628
2629         [Test]
2630         [ExpectedException (typeof (IndexOutOfRangeException))]
2631         public void Clear_LengthOverflow () 
2632         {
2633                 byte[] array = new byte [16];
2634                 Array.Clear (array, Int32.MaxValue, 4);
2635         }
2636
2637         [Test]
2638         [ExpectedException (typeof (ArgumentException))]
2639         public void Copy_SourceIndexOverflow () 
2640         {
2641                 byte[] array = new byte [16];
2642                 Array.Copy (array, Int32.MaxValue, array, 8, 8);
2643         }
2644
2645         [Test]
2646         [ExpectedException (typeof (ArgumentException))]
2647         public void Copy_DestinationIndexOverflow () 
2648         {
2649                 byte[] array = new byte [16];
2650                 Array.Copy (array, 8, array, Int32.MaxValue, 8);
2651         }
2652
2653         [Test]
2654         [ExpectedException (typeof (ArgumentException))]
2655         public void Copy_LengthOverflow () 
2656         {
2657                 byte[] array = new byte [16];
2658                 Array.Copy (array, 8, array, 8, Int32.MaxValue);
2659         }
2660
2661         [Test]
2662         [ExpectedException (typeof (ArgumentException))]
2663         public void Reverse_IndexOverflow () 
2664         {
2665                 byte[] array = new byte [16];
2666                 Array.Reverse (array, Int32.MaxValue, 8);
2667         }
2668
2669         [Test]
2670         [ExpectedException (typeof (ArgumentException))]
2671         public void Reverse_LengthOverflow () 
2672         {
2673                 byte[] array = new byte [16];
2674                 Array.Reverse (array, 8, Int32.MaxValue);
2675         }
2676         
2677         public struct CharX : IComparable {
2678                 public char c;
2679         
2680                 public CharX (char c)
2681                 {
2682                         this.c = c;
2683                 }
2684         
2685                 public int CompareTo (object obj)
2686                 {
2687                         if (obj is CharX)
2688                                 return c.CompareTo (((CharX) obj).c);
2689                         else
2690                                 return c.CompareTo (obj);
2691                 }
2692         }
2693
2694         [Test]
2695         public void BinarySearch_ArgPassingOrder ()
2696         {
2697                 //
2698                 // This tests that arguments are passed to the comprer in the correct
2699                 // order. The IComparable of the *array* elements must get called, not
2700                 // that of the search object.
2701                 //
2702                 CharX [] x = { new CharX ('a'), new CharX ('b'), new CharX ('c') };
2703                 Assert.AreEqual (1, Array.BinarySearch (x, 'b'));
2704         }
2705
2706         class Comparer: IComparer {
2707
2708                 private bool called = false;
2709
2710                 public bool Called {
2711                         get {
2712                                 bool result = called;
2713                                 called = false;
2714                                 return called;
2715                         }
2716                 }
2717
2718                 public int Compare (object x, object y)
2719                 {
2720                         called = true;
2721                         return 0;
2722                 }
2723         }
2724
2725         [Test]
2726         public void BinarySearch1_EmptyList ()
2727         {
2728                 int[] array = new int[0];
2729                 Assert.AreEqual (- 1, Array.BinarySearch (array, 0), "BinarySearch");
2730         }
2731
2732         [Test]
2733         public void BinarySearch2_EmptyList ()
2734         {
2735                 int[] array = new int[0];
2736                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 0, 0), "BinarySearch");
2737         }
2738
2739         [Test]
2740         public void BinarySearch3_EmptyList ()
2741         {
2742                 Comparer comparer = new Comparer ();
2743                 int[] array = new int[0];
2744                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, comparer), "BinarySearch");
2745                 // bug 77030 - the comparer isn't called for an empty array/list
2746                 Assert.IsTrue (!comparer.Called, "Called");
2747         }
2748
2749         [Test]
2750         public void BinarySearch4_EmptyList ()
2751         {
2752                 Comparer comparer = new Comparer ();
2753                 int[] array = new int[0];
2754                 Assert.AreEqual (-1, Array.BinarySearch (array, 0, 0, comparer), "BinarySearch");
2755                 // bug 77030 - the comparer isn't called for an empty array/list
2756                 Assert.IsTrue (!comparer.Called, "Called");
2757         }
2758
2759 #if NET_2_0
2760         [Test]
2761         [ExpectedException (typeof (ArgumentNullException))]
2762         public void AsReadOnly_NullArray ()
2763         {
2764                 Array.AsReadOnly <int> (null);
2765         }
2766
2767         [Test]
2768         public void ReadOnly_Count ()
2769         {
2770                 Assert.AreEqual (10, Array.AsReadOnly (new int [10]).Count);
2771         }
2772
2773         [Test]
2774         public void ReadOnly_Contains ()
2775         {
2776                 int[] arr = new int [2];
2777                 arr [0] = 3;
2778                 arr [1] = 5;
2779                 IList<int> a = Array.AsReadOnly (arr);
2780
2781                 Assert.IsTrue (a.Contains (3));
2782                 Assert.IsTrue (!a.Contains (6));
2783         }
2784
2785         [Test]
2786         public void ReadOnly_IndexOf ()
2787         {
2788                 int[] arr = new int [2];
2789                 arr [0] = 3;
2790                 arr [1] = 5;
2791                 IList<int> a = Array.AsReadOnly (arr);
2792
2793                 Assert.AreEqual (0, a.IndexOf (3));
2794                 Assert.AreEqual (1, a.IndexOf (5));
2795                 Assert.AreEqual (-1, a.IndexOf (6));
2796         }
2797
2798         [Test]
2799         public void ReadOnly_Indexer ()
2800         {
2801                 int[] arr = new int [2];
2802                 arr [0] = 3;
2803                 arr [1] = 5;
2804                 IList<int> a = Array.AsReadOnly (arr);
2805
2806                 Assert.AreEqual (3, a [0]);
2807                 Assert.AreEqual (5, a [1]);
2808
2809                 /* Check that modifications to the original array are visible */
2810                 arr [0] = 6;
2811                 Assert.AreEqual (6, a [0]);
2812         }
2813
2814         [Test]
2815         public void ReadOnly_Enumerator ()
2816         {
2817                 int[] arr = new int [10];
2818
2819                 for (int i = 0; i < 10; ++i)
2820                         arr [i] = i;
2821
2822                 int sum = 0;
2823                 foreach (int i in Array.AsReadOnly (arr))
2824                         sum += i;
2825
2826                 Assert.AreEqual (45, sum);
2827         }
2828
2829         [Test]
2830         public void ReadOnly_CopyTo ()
2831         {
2832                 int[] arr = new int [2];
2833                 arr [0] = 3;
2834                 arr [1] = 5;
2835                 IList<int> a = Array.AsReadOnly (arr);
2836
2837                 int[] arr2 = new int [3];
2838                 a.CopyTo (arr2, 1);
2839
2840                 Assert.AreEqual (0, arr2 [0]);
2841                 Assert.AreEqual (3, arr2 [1]);
2842                 Assert.AreEqual (5, arr2 [2]);
2843         }
2844
2845         [Test]
2846         public void Resize ()
2847         {
2848                 int [] arr = new int [] { 1, 3, 5 };
2849                 Array.Resize <int> (ref arr, 3);
2850                 Assert.AreEqual (3, arr.Length, "#A1");
2851                 Assert.AreEqual (1, arr [0], "#A2");
2852                 Assert.AreEqual (3, arr [1], "#A3");
2853                 Assert.AreEqual (5, arr [2], "#A4");
2854
2855                 Array.Resize <int> (ref arr, 2);
2856                 Assert.AreEqual (2, arr.Length, "#B1");
2857                 Assert.AreEqual (1, arr [0], "#B2");
2858                 Assert.AreEqual (3, arr [1], "#B3");
2859
2860                 Array.Resize <int> (ref arr, 4);
2861                 Assert.AreEqual (4, arr.Length, "#C1");
2862                 Assert.AreEqual (1, arr [0], "#C2");
2863                 Assert.AreEqual (3, arr [1], "#C3");
2864                 Assert.AreEqual (0, arr [2], "#C4");
2865                 Assert.AreEqual (0, arr [3], "#C5");
2866         }
2867
2868         [Test]
2869         public void Resize_null ()
2870         {
2871                 int [] arr = null;
2872                 Array.Resize (ref arr, 10);
2873                 Assert.AreEqual (arr.Length, 10);
2874         }
2875
2876         [Test]
2877         public void Test_ContainsAndIndexOf_EquatableItem ()
2878         {
2879                 EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
2880
2881                 Assert.AreEqual (0, Array.IndexOf<EquatableClass> (list, list[0]), "#0");
2882                 Assert.AreEqual (0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)), "#1");
2883                 Assert.AreEqual (2, Array.LastIndexOf<EquatableClass> (list, list[0]), "#2");
2884                 Assert.AreEqual (2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)), "#3");
2885         }
2886
2887         public class EquatableClass : IEquatable<EquatableClass>
2888         {
2889                 int _x;
2890                 public EquatableClass (int x)
2891                 {
2892                         _x = x;
2893                 }
2894
2895                 public bool Equals (EquatableClass other)
2896                 {
2897                         return this._x == other._x;
2898                 }
2899         }
2900
2901         [Test]
2902         public void AsIList ()
2903         {
2904                 IList<int> arr = new int [10];
2905                 arr [0] = 5;
2906                 Assert.AreEqual (5, arr [0]);
2907
2908                 IList<FooStruct> arr2 = new FooStruct [10];
2909                 FooStruct s = new FooStruct ();
2910                 s.i = 11;
2911                 s.j = 22;
2912                 arr2 [5] = s;
2913                 s = arr2 [5];
2914                 Assert.AreEqual (11, s.i);
2915                 Assert.AreEqual (22, s.j);
2916
2917                 IList<string> arr3 = new string [10];
2918                 arr3 [5] = "ABC";
2919                 Assert.AreEqual ("ABC", arr3 [5]);
2920         }
2921
2922         struct FooStruct {
2923                 public int i, j;
2924         }
2925
2926 #if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
2927         [Test]
2928         // From bug #80563
2929         public void ICollectionNull ()
2930         {
2931                 ICollection<object> test;
2932                 
2933                 test = new List<object>();
2934                 Assert.AreEqual (test.Contains (null), false, "list<o>");
2935
2936                 test = new object[] {};
2937                 Assert.AreEqual (test.Contains (null), false, "empty array");
2938
2939                 test = new object[] {null};
2940                 Assert.AreEqual (test.Contains (null), true, "array with null");
2941
2942                 test = new List<object>(test);
2943                 Assert.AreEqual (test.Contains (null), true, "List<object> with test");
2944                 
2945                 test = new object[] {new object()};
2946                 Assert.AreEqual (test.Contains (null), false, "array with object");
2947
2948                 test = new List<object>(test);
2949                 Assert.AreEqual (test.Contains (null), false, "array with test");
2950         }
2951 #endif // TARGET_JVM
2952 #endif
2953
2954         #region Bug 80299
2955
2956         enum ByteEnum : byte {}
2957         enum IntEnum : int {}
2958
2959         [Test]
2960         public void TestByteEnumArrayToByteArray ()
2961         {
2962                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2963                 byte[] b = new byte[a.Length];
2964                 a.CopyTo (b, 0);
2965         }
2966
2967         [Test]
2968         public void TestByteEnumArrayToIntArray ()
2969         {
2970                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2971                 int[] b = new int[a.Length];
2972                 a.CopyTo (b, 0);
2973         }
2974
2975         [Test]
2976         [ExpectedException (typeof (ArrayTypeMismatchException))]
2977         public void TestIntEnumArrayToByteArray ()
2978         {
2979                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2980                 byte[] b = new byte[a.Length];
2981                 a.CopyTo (b, 0);
2982         }
2983
2984         [Test]
2985         public void TestIntEnumArrayToIntArray ()
2986         {
2987                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2988                 int[] b = new int[a.Length];
2989                 a.CopyTo (b, 0);
2990         }
2991
2992         #endregion
2993
2994 #if NET_2_0
2995         [Test] // bug #322248
2996         public void IEnumerator_Reset ()
2997         {
2998                 int[] array = new int[] { 1, 2, 3};
2999                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3000                 Assert.IsTrue (e.MoveNext (), "#A1");
3001                 Assert.AreEqual (1, e.Current, "#A2");
3002                 Assert.IsTrue (e.MoveNext (), "#A3");
3003                 Assert.AreEqual (2, e.Current, "#A4");
3004
3005                 e.Reset ();
3006
3007                 Assert.IsTrue (e.MoveNext (), "#C1");
3008                 Assert.AreEqual (1, e.Current, "#C2");
3009         }
3010
3011         [Test]
3012         public void IEnumerator_Current_Finished ()
3013         {
3014                 int[] array = new int[] { 1, 2, 3 };
3015                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3016                 Assert.IsTrue (e.MoveNext (), "#A1");
3017                 Assert.AreEqual (1, e.Current, "#A2");
3018                 Assert.IsTrue (e.MoveNext (), "#A3");
3019                 Assert.AreEqual (2, e.Current, "#A4");
3020                 Assert.IsTrue (e.MoveNext (), "#A5");
3021                 Assert.AreEqual (3, e.Current, "#A6");
3022                 Assert.IsTrue (!e.MoveNext (), "#A6");
3023
3024                 try {
3025                         Assert.Fail ("#B1:" + e.Current);
3026                 } catch (InvalidOperationException ex) {
3027                         // Enumeration already finished
3028                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
3029                         Assert.IsNull (ex.InnerException, "#B3");
3030                         Assert.IsNotNull (ex.Message, "#B4");
3031                 }
3032         }
3033
3034         [Test]
3035         public void IEnumerator_Current_NotStarted ()
3036         {
3037                 int[] array = new int[] { 1, 2, 3 };
3038                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3039
3040                 try {
3041                         Assert.Fail ("#A1:" + e.Current);
3042                 } catch (InvalidOperationException ex) {
3043                         // Enumeration has not started. Call MoveNext
3044                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
3045                         Assert.IsNull (ex.InnerException, "#A3");
3046                         Assert.IsNotNull (ex.Message, "#A4");
3047                 }
3048         }
3049
3050         [Test]
3051         public void IEnumerator_Current_Reset ()
3052         {
3053                 int[] array = new int[] { 1, 2, 3 };
3054                 IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
3055                 e.MoveNext ();
3056                 e.Reset ();
3057
3058                 try {
3059                         Assert.Fail ("#B1:" + e.Current);
3060                 } catch (InvalidOperationException ex) {
3061                         // Enumeration has not started. Call MoveNext
3062                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
3063                         Assert.IsNull (ex.InnerException, "#B3");
3064                         Assert.IsNotNull (ex.Message, "#B4");
3065                 }
3066         }
3067
3068         public void ICollection_IsReadOnly() {
3069                 ICollection<string> arr = new string [10];
3070
3071                 Assert.IsTrue (arr.IsReadOnly);
3072         }
3073 #endif
3074
3075         [Test]
3076         [ExpectedException (typeof (NotSupportedException))]
3077         public void ArrayCreateInstanceOfVoid ()
3078         {
3079                 Array.CreateInstance (typeof (void), 42);
3080         }
3081
3082         class Foo<T> {}
3083
3084         [Test]
3085         [ExpectedException (typeof (NotSupportedException))]
3086         public void ArrayCreateInstanceOfOpenGenericType ()
3087         {
3088                 Array.CreateInstance (typeof (Foo<>), 42);
3089         }
3090
3091         [Test]
3092         [ExpectedException (typeof (IndexOutOfRangeException))]
3093         public void ClearNegativeLength ()
3094         {
3095                 Array.Clear (new int [] { 1, 2 }, 0, -1);
3096         }
3097
3098         [Test]
3099         [ExpectedException (typeof (ArgumentException))]
3100         public void MultiDimension_IList_setItem ()
3101         {
3102                 IList array = new int [1, 1];
3103                 array [0] = 2;
3104         }
3105
3106         [Test]
3107         [ExpectedException (typeof (ArgumentException))]
3108         public void MultiDimension_IList_getItem ()
3109         {
3110                 IList array = new int [1, 1];
3111                 int a = (int) array [0];
3112         }
3113
3114         [Test]
3115         public void SetValue_Nullable () {
3116                 Array array = Array.CreateInstance (typeof (int?), 7);
3117
3118                 object o = 42;
3119
3120                 array.SetValue (o, 0);
3121                 Assert.AreEqual (42, array.GetValue (0));
3122
3123                 array.SetValue (null, 0);
3124                 Assert.AreEqual (null, array.GetValue (0));
3125         }
3126
3127 #if NET_4_0
3128         [Test]
3129         [ExpectedException (typeof (ArgumentException))]
3130         public void CompareToWithJaggedArray () {
3131                 IStructuralComparable a = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
3132                 IStructuralComparable b = new int[][] { new int [] { 1,2 }, new int [] { 3,4 }};
3133                 a.CompareTo (b, Comparer<object>.Default);
3134         }
3135
3136         [Test]
3137         [ExpectedException (typeof (ArgumentException))]
3138         public void CompareToWithArrayOfTheWrongKind () {
3139                 IStructuralComparable a = new int[] { 1, 2 };
3140                 IStructuralComparable b = new double[] { 1, 2 };
3141                 a.CompareTo (b, Comparer<object>.Default);
3142         }
3143
3144         [Test]
3145         [ExpectedException (typeof (ArgumentException))]
3146         public void CompareToWithNonArrayType () {
3147                 IStructuralComparable a = new int[] { 1, 2 };
3148                 a.CompareTo (99, Comparer<object>.Default);
3149         }
3150
3151         [Test]
3152         [ExpectedException (typeof (ArgumentException))]
3153         public void CompareToWithNonArrayOfDifferentSize () {
3154                 IStructuralComparable a = new int[] { 1, 2 };
3155                 IStructuralComparable b = new int[] { 1, 2, 3 };
3156                 a.CompareTo (b, Comparer<object>.Default);
3157         }
3158
3159         [Test]
3160         [ExpectedException (typeof (ArgumentException))]
3161         public void CompareToWithMultiDimArray1 () {
3162                 IStructuralComparable a = new int [2,2] { {10, 10 }, { 10, 10 } };
3163                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3164                 a.CompareTo (b, Comparer<object>.Default);
3165         }
3166
3167         [Test]
3168         [ExpectedException (typeof (ArgumentException))]
3169         public void CompareToWithMultiDimArray2 () {
3170                 IStructuralComparable a = new int [2] { 10, 10 };
3171                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3172                 a.CompareTo (b, Comparer<object>.Default);
3173         }
3174
3175         [Test]
3176         [ExpectedException (typeof (ArgumentException))]
3177         public void CompareToWithMultiDimArray3 () {
3178                 IStructuralComparable a = new int [4] { 10, 10, 10, 10 };
3179                 IStructuralComparable b = new int [2,2] { {10, 10 }, { 10, 10 } };
3180                 a.CompareTo (b, Comparer<object>.Default);
3181         }
3182
3183         [Test]
3184         [ExpectedException (typeof (IndexOutOfRangeException))]
3185         public void CompareToWithBoundedArray1 () {
3186                 IStructuralComparable a = new int [2] { 10, 10 };
3187                 Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
3188                 IStructuralComparable b = ab;
3189                 ab.SetValue (10, 5);
3190                 ab.SetValue (10, 6);
3191
3192                 a.CompareTo (b, Comparer<object>.Default);
3193         }
3194
3195         [Test]
3196         [ExpectedException (typeof (IndexOutOfRangeException))]
3197         public void CompareToWithBoundedArray2 () {
3198                 IStructuralComparable a = new int [2] { 10, 10 };
3199                 Array ab = Array.CreateInstance (typeof (int), new int[] { 2 }, new int [] { 5 });
3200                 IStructuralComparable b = ab;
3201                 ab.SetValue (10, 5);
3202                 ab.SetValue (10, 6);
3203
3204                 //Yes, CompareTo simply doesn't work with bounded arrays!
3205                 b.CompareTo (b, Comparer<object>.Default);
3206         }
3207
3208         [Test]
3209         [ExpectedException (typeof (NullReferenceException))]
3210         public void CompareToWithNullComparer () {
3211                 IStructuralComparable a = new int[] { 1, 2 };
3212                 IStructuralComparable b = new int[] { 1, 2 };
3213                 a.CompareTo (b, null);
3214         }
3215
3216         [Test]
3217         public void CompareToWithNullArray () {
3218                 IStructuralComparable a = new int[] { 1, 2 };
3219                 Assert.AreEqual (1, a.CompareTo (null, Comparer<object>.Default));
3220         }
3221
3222         [Test]
3223         public void CompareToWithGoodArrays () {
3224                 IStructuralComparable a = new int[] { 10, 20 };
3225                 Assert.AreEqual (0, a.CompareTo (a, Comparer<object>.Default));
3226                 Assert.AreEqual (0, a.CompareTo (new int [] { 10, 20 }, Comparer<object>.Default));
3227                 Assert.AreEqual (-1, a.CompareTo (new int [] { 11, 20 }, Comparer<object>.Default));
3228                 Assert.AreEqual (-1, a.CompareTo (new int [] { 10, 21 }, Comparer<object>.Default));
3229                 Assert.AreEqual (1, a.CompareTo (new int [] { 9, 20 }, Comparer<object>.Default));
3230                 Assert.AreEqual (1, a.CompareTo (new int [] { 10, 19 }, Comparer<object>.Default));
3231         }
3232
3233         [Test]
3234         public void IStructuralEquatable_Equals ()
3235         {
3236                 IStructuralEquatable array = new int[] {1, 2, 3};
3237                 IStructuralEquatable array2 = new int[] {1, 2, 3};
3238                 Assert.AreEqual (false, array.Equals (null, null));
3239                 Assert.AreEqual (true, array.Equals (array, null));
3240                 Assert.AreEqual (true, array.Equals (array2, EqualityComparer<int>.Default));
3241         }
3242
3243         [Test]
3244         [ExpectedException (typeof (NullReferenceException))]
3245         public void IStructuralEquatable_Equals_NoComparer ()
3246         {
3247                 IStructuralEquatable array = new int[] {1, 2, 3};
3248                 IStructuralComparable array2 = new int[] {1, 2, 3};
3249                 array.Equals (array2, null);
3250         }
3251
3252         [Test]
3253         [ExpectedException (typeof (ArgumentException))]
3254         public void IStructuralEquatable_Equals_ComparerThrows ()
3255         {
3256                 IStructuralEquatable array = new int[] {1, 2, 3};
3257                 IStructuralComparable array2 = new int[] {1, 2, 3};
3258                 array.Equals (array2, EqualityComparer<long>.Default);
3259         }
3260
3261 #endif
3262
3263 }
3264 }