CopyTo() публичный Метод

public CopyTo ( System array, int index ) : void
array System
index int
Результат void
        public static void CopyExceptions()
        {
            CmsRecipient a0 = s_cr0;
            CmsRecipient a1 = s_cr1;
            CmsRecipient a2 = s_cr2;

            CmsRecipientCollection c = new CmsRecipientCollection();
            c.Add(a0);
            c.Add(a1);
            c.Add(a2);

            CmsRecipient[] a = new CmsRecipient[3];
            Assert.Throws<ArgumentNullException>(() => c.CopyTo(null, 0));
            Assert.Throws<ArgumentOutOfRangeException>(() => c.CopyTo(a, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => c.CopyTo(a, 3));
            Assert.Throws<ArgumentException>(() => c.CopyTo(a, 1));

            ICollection ic = c;
            Assert.Throws<ArgumentNullException>(() => ic.CopyTo(null, 0));
            Assert.Throws<ArgumentOutOfRangeException>(() => ic.CopyTo(a, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => ic.CopyTo(a, 3));
            Assert.Throws<ArgumentException>(() => ic.CopyTo(a, 1));
            Assert.Throws<ArgumentException>(() => ic.CopyTo(new CmsRecipient[2, 2], 1));
            Assert.Throws<InvalidCastException>(() => ic.CopyTo(new int[10], 1));

            // Array has non-zero lower bound
            Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
            Assert.Throws<IndexOutOfRangeException>(() => ic.CopyTo(array, 0));
        }
        private static void AssertEquals(CmsRecipientCollection c, IList<CmsRecipient> expected)
        {
            Assert.Equal(expected.Count, c.Count);

            for (int i = 0; i < c.Count; i++)
            {
                Assert.Equal(expected[i], c[i]);
            }

            int index = 0;
            foreach (CmsRecipient a in c)
            {
                Assert.Equal(expected[index++], a);
            }
            Assert.Equal(c.Count, index);

            ValidateEnumerator(c.GetEnumerator(), expected);
            ValidateEnumerator(((ICollection)c).GetEnumerator(), expected);

            {
                CmsRecipient[] dumped = new CmsRecipient[c.Count + 3];
                c.CopyTo(dumped, 2);
                Assert.Equal(null, dumped[0]);
                Assert.Equal(null, dumped[1]);
                Assert.Equal(null, dumped[dumped.Length - 1]);
                Assert.Equal<CmsRecipient>(expected, dumped.Skip(2).Take(c.Count));
            }

            {
                CmsRecipient[] dumped = new CmsRecipient[c.Count + 3];
                ((ICollection)c).CopyTo(dumped, 2);
                Assert.Equal(null, dumped[0]);
                Assert.Equal(null, dumped[1]);
                Assert.Equal(null, dumped[dumped.Length - 1]);
                Assert.Equal<CmsRecipient>(expected, dumped.Skip(2).Take(c.Count));
            }
        }
        public static void CopyExceptions()
        {
            CmsRecipient a0 = s_cr0;
            CmsRecipient a1 = s_cr1;
            CmsRecipient a2 = s_cr2;

            CmsRecipientCollection c = new CmsRecipientCollection();
            c.Add(a0);
            c.Add(a1);
            c.Add(a2);

            CmsRecipient[] a = new CmsRecipient[3];
            Assert.Throws<ArgumentNullException>(() => c.CopyTo(null, 0));
            Assert.Throws<ArgumentOutOfRangeException>(() => c.CopyTo(a, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => c.CopyTo(a, 3));
            Assert.Throws<ArgumentException>(() => c.CopyTo(a, 1));

            ICollection ic = c;
            Assert.Throws<ArgumentNullException>(() => ic.CopyTo(null, 0));
            Assert.Throws<ArgumentOutOfRangeException>(() => ic.CopyTo(a, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => ic.CopyTo(a, 3));
            Assert.Throws<ArgumentException>(() => ic.CopyTo(a, 1));
            Assert.Throws<ArgumentException>(() => ic.CopyTo(new CmsRecipient[2, 2], 1));
            Assert.Throws<InvalidCastException>(() => ic.CopyTo(new int[10], 1));
        }