public void TestCopyTo() { { bool errorThrown = false; try { Char[] c1 = new Char[2]; c1.CopyTo(null, 2); } catch (ArgumentNullException) { errorThrown = true; } Assert("#E61", errorThrown); } { bool errorThrown = false; try { Char[] c1 = new Char[2]; Char[,] c2 = new Char[2,2]; c1.CopyTo(c2, 2); } catch (ArgumentException) { errorThrown = true; } Assert("#E62", errorThrown); } { bool errorThrown = false; try { Char[,] c1 = new Char[2,2]; Char[] c2 = new Char[2]; c1.CopyTo(c2, -1); } catch (RankException) { errorThrown = true; } Assert("#E63", errorThrown); } { bool errorThrown = false; try { Char[,] c1 = new Char[2,2]; Char[] c2 = new Char[2]; c1.CopyTo(c2, 2); } catch (RankException) { errorThrown = true; } Assert("#E64", errorThrown); } { bool errorThrown = false; try { Char[] c1 = new Char[2]; Char[] c2 = new Char[2]; c1.CopyTo(c2, -1); } catch (ArgumentOutOfRangeException) { errorThrown = true; } Assert("#E65", errorThrown); } { bool errorThrown = false; try { Char[] c1 = new Char[2]; Char[] c2 = new Char[2]; c1.CopyTo(c2, 3); } catch (ArgumentException) { errorThrown = true; } Assert("#E66", errorThrown); } { bool errorThrown = false; try { Char[] c1 = new Char[2]; Char[] c2 = new Char[2]; c1.CopyTo(c2, 1); } catch (ArgumentException) { errorThrown = true; } Assert("#E67", errorThrown); } { bool errorThrown = false; try { String[] c1 = new String[2]; // TODO: this crashes mono if there are null // values in the array. c1[1] = "hey"; c1[0] = "you"; Char[] c2 = new Char[2]; c2[1] = 'a'; c2[0] = 'z'; c1.CopyTo(c2, 0); } catch (ArrayTypeMismatchException) { errorThrown = true; } Assert("#E68", errorThrown); } Char[] orig = {'a', 'b', 'c', 'd'}; Char[] copy = new Char[10]; Array.Clear(copy, 0, copy.Length); orig.CopyTo(copy, 3); AssertEquals("#E69", (char)0, copy[0]); AssertEquals("#E70", (char)0, copy[1]); AssertEquals("#E71", (char)0, copy[2]); AssertEquals("#E72", orig[0], copy[3]); AssertEquals("#E73", orig[1], copy[4]); AssertEquals("#E74", orig[2], copy[5]); AssertEquals("#E75", orig[3], copy[6]); AssertEquals("#E76", (char)0, copy[7]); AssertEquals("#E77", (char)0, copy[8]); AssertEquals("#E78", (char)0, copy[9]); { // The following is valid and must not throw an exception. bool errorThrown = false; try { int[] src = new int [0]; int[] dest = new int [0]; src.CopyTo (dest, 0); } catch (ArgumentException) { errorThrown = true; } Assert("#E79", !errorThrown); } { // bug #38812 bool errorThrown = false; try { CClass[] src = new CClass [] { new CClass () }; BClass[] dest = new BClass [1]; src.CopyTo (dest, 0); } catch (ArrayTypeMismatchException) { errorThrown = true; } Assert("#E80", errorThrown); } }