当前位置: 首页>>代码示例>>C#>>正文


C# ConcurrentStack.CopyTo方法代码示例

本文整理汇总了C#中ConcurrentStack.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentStack.CopyTo方法的具体用法?C# ConcurrentStack.CopyTo怎么用?C# ConcurrentStack.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConcurrentStack的用法示例。


在下文中一共展示了ConcurrentStack.CopyTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Push_5_Integers

        public void Push_5_Integers()
        {
            var expected = new int[] { 4, 3, 2, 1, 0 };
            ConcurrentStack<int> stack = new ConcurrentStack<int>();

            for (var i = 0; i < 5; i++)
            {
                stack.Push(i);
            }

            var actual = new int[5];
            stack.CopyTo(actual, 0);

            CollectionAssert.AreEqual(expected, actual);
        }
开发者ID:EBrown8534,项目名称:Framework,代码行数:15,代码来源:ConcurrentStackTests.cs

示例2: RunConcurrentStackTest5_CtorAndCopyToAndToArray

        // Instantiates the stack w/ the enumerator ctor and validates the resulting copyto & toarray.
        private static bool RunConcurrentStackTest5_CtorAndCopyToAndToArray(int count)
        {
            TestHarness.TestLog("* RunConcurrentStackTest5_CtorAndCopyToAndToArray()");

            int[] arr = new int[count];
            for (int i = 0; i < count; i++) arr[i] = i;
            ConcurrentStack<int> s = new ConcurrentStack<int>(arr);

            // try toarray.
            int[] sa1 = s.ToArray();
            if (sa1.Length != arr.Length)
            {
                TestHarness.TestLog("  > ToArray resulting array is diff length: got {0}, wanted {1}",
                    sa1.Length, arr.Length);
                return false;
            }
            for (int i = 0; i < sa1.Length; i++)
            {
                if (sa1[i] != arr[count - i - 1])
                {
                    TestHarness.TestLog("  > ToArray returned an array w/ diff contents: got {0}, wanted {1}",
                        sa1[i], arr[count - i - 1]);
                    return false;
                }
            }

            int[] sa2 = new int[count];
            s.CopyTo(sa2, 0);
            if (sa2.Length != arr.Length)
            {
                TestHarness.TestLog("  > CopyTo(int[]) resulting array is diff length: got {0}, wanted {1}",
                    sa2.Length, arr.Length);
                return false;
            }
            for (int i = 0; i < sa2.Length; i++)
            {
                if (sa2[i] != arr[count - i - 1])
                {
                    TestHarness.TestLog("  > CopyTo(int[]) returned an array w/ diff contents: got {0}, wanted {1}",
                        sa2[i], arr[count - i - 1]);
                    return false;
                }
            }

            object[] sa3 = new object[count]; // test array variance.
            ((System.Collections.ICollection)s).CopyTo(sa3, 0);
            if (sa3.Length != arr.Length)
            {
                TestHarness.TestLog("  > CopyTo(object[]) resulting array is diff length: got {0}, wanted {1}",
                    sa3.Length, arr.Length);
                return false;
            }
            for (int i = 0; i < sa3.Length; i++)
            {
                if ((int)sa3[i] != arr[count - i - 1])
                {
                    TestHarness.TestLog("  > CopyTo(object[]) returned an array w/ diff contents: got {0}, wanted {1}",
                        sa3[i], arr[count - i - 1]);
                    return false;
                }
            }

            return true;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:65,代码来源:CdsTests.cs

示例3: Test8_Exceptions

        public static void Test8_Exceptions()
        {
            ConcurrentStack<int> stack = null;
            Assert.Throws<ArgumentNullException>(
               () => stack = new ConcurrentStack<int>((IEnumerable<int>)null));
               // "Test8_Exceptions:  The constructor didn't throw ANE when null collection passed");

            stack = new ConcurrentStack<int>();
            //CopyTo
            Assert.Throws<ArgumentNullException>(
               () => stack.CopyTo(null, 0));
               // "Test8_Exceptions:  CopyTo didn't throw ANE when null array passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.CopyTo(new int[1], -1));
               // "Test8_Exceptions:  CopyTo didn't throw AORE when negative array index passed");

            //PushRange
            Assert.Throws<ArgumentNullException>(
               () => stack.PushRange(null));
               // "Test8_Exceptions:  PushRange didn't throw ANE when null array passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.PushRange(new int[1], 0, -1));
               // "Test8_Exceptions:  PushRange didn't throw AORE when negative count passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.PushRange(new int[1], -1, 1));
               // "Test8_Exceptions:  PushRange didn't throw AORE when negative index passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.PushRange(new int[1], 2, 1));
               // "Test8_Exceptions:  PushRange didn't throw AORE when start index > array length");
            Assert.Throws<ArgumentException>(
               () => stack.PushRange(new int[1], 0, 10));
               // "Test8_Exceptions:  PushRange didn't throw AE when count + index > array length");

            //PopRange
            Assert.Throws<ArgumentNullException>(
               () => stack.TryPopRange(null));
               // "Test8_Exceptions:  TryPopRange didn't throw ANE when null array passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.TryPopRange(new int[1], 0, -1));
               // "Test8_Exceptions:  TryPopRange didn't throw AORE when negative count passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.TryPopRange(new int[1], -1, 1));
               // "Test8_Exceptions:  TryPopRange didn't throw AORE when negative index passed");
            Assert.Throws<ArgumentOutOfRangeException>(
               () => stack.TryPopRange(new int[1], 2, 1));
               // "Test8_Exceptions:  TryPopRange didn't throw AORE when start index > array length");
            Assert.Throws<ArgumentException>(
               () => stack.TryPopRange(new int[1], 0, 10));
               // "Test8_Exceptions:  TryPopRange didn't throw AE when count + index > array length");
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:50,代码来源:ConcurrentStackTests.cs

示例4: Test5_CtorAndCopyToAndToArray

        // Instantiates the stack w/ the enumerator ctor and validates the resulting copyto & toarray.
        private static void Test5_CtorAndCopyToAndToArray(int count)
        {
            int[] arr = new int[count];
            for (int i = 0; i < count; i++) arr[i] = i;
            ConcurrentStack<int> s = new ConcurrentStack<int>(arr);

            // try toarray.
            int[] sa1 = s.ToArray();
            Assert.Equal(arr.Length, sa1.Length);

            for (int i = 0; i < sa1.Length; i++)
            {
                Assert.Equal(arr[count - i - 1], sa1[i]);
            }

            int[] sa2 = new int[count];
            s.CopyTo(sa2, 0);
            Assert.Equal(arr.Length, sa2.Length);

            for (int i = 0; i < sa2.Length; i++)
            {
                Assert.Equal(arr[count - i - 1], sa2[i]);
            }

            object[] sa3 = new object[count]; // test array variance.
            ((System.Collections.ICollection)s).CopyTo(sa3, 0);
            Assert.Equal(arr.Length, sa3.Length);

            for (int i = 0; i < sa3.Length; i++)
            {
                Assert.Equal(arr[count - i - 1], (int)sa3[i]);
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:34,代码来源:ConcurrentStackTests.cs


注:本文中的ConcurrentStack.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。