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


C# ConcurrentQueue.CopyTo方法代码示例

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


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

示例1: Test7_Exceptions

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

            queue = new ConcurrentQueue<int>();
            //CopyTo
            Assert.Throws<ArgumentNullException>( () => queue.CopyTo(null, 0));
            // "Test7_Exceptions:  CopyTo didn't throw ANE when null array passed");
            Assert.Throws<ArgumentOutOfRangeException>( () => queue.CopyTo(new int[1], -1));
            // "Test7_Exceptions:  CopyTo didn't throw AORE when negative array index passed");
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:14,代码来源:ConcurrentQueueTests.cs

示例2: RunConcurrentQueueTest5_CtorAndCopyToAndToArray

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

            int[] arr = new int[count];
            for (int i = 0; i < count; i++) arr[i] = i;
            ConcurrentQueue<int> s = new ConcurrentQueue<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[i])
                {
                    TestHarness.TestLog("  > ToArray returned an array w/ diff contents: got {0}, wanted {1}",
                        sa1[i], arr[i]);
                    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[i])
                {
                    TestHarness.TestLog("  > CopyTo(int[]) returned an array w/ diff contents: got {0}, wanted {1}",
                        sa2[i], arr[i]);
                    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[i])
                {
                    TestHarness.TestLog("  > CopyTo(object[]) returned an array w/ diff contents: got {0}, wanted {1}",
                        sa3[i], arr[i]);
                    return false;
                }
            }

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

示例3: CopyTo_AllItemsCopiedAtCorrectLocation

        public void CopyTo_AllItemsCopiedAtCorrectLocation(int count, bool viaInterface)
        {
            var q = new ConcurrentQueue<int>(Enumerable.Range(0, count));
            var c = (ICollection)q;
            int[] arr = new int[count];

            if (viaInterface)
            {
                c.CopyTo(arr, 0);
            }
            else
            {
                q.CopyTo(arr, 0);
            }
            Assert.Equal(q, arr);

            if (count > 1)
            {
                int toRemove = count / 2;
                int remaining = count - toRemove;
                for (int i = 0; i < toRemove; i++)
                {
                    int item;
                    Assert.True(q.TryDequeue(out item));
                    Assert.Equal(i, item);
                }

                if (viaInterface)
                {
                    c.CopyTo(arr, 1);
                }
                else
                {
                    q.CopyTo(arr, 1);
                }

                Assert.Equal(0, arr[0]);
                for (int i = 0; i < remaining; i++)
                {
                    Assert.Equal(arr[1 + i], i + toRemove);
                }
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:43,代码来源:ConcurrentQueueTests.cs

示例4: CopyTo_Empty_Success

 public void CopyTo_Empty_Success()
 {
     var q = new ConcurrentQueue<int>();
     q.CopyTo(Array.Empty<int>(), 0);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:ConcurrentQueueTests.cs

示例5: Test5_CtorAndCopyToAndToArray

        // Instantiates the queue w/ the enumerator ctor and validates the resulting copyto & toarray.
        public static void Test5_CtorAndCopyToAndToArray(int count)
        {
            int[] arr = new int[count];
            for (int i = 0; i < count; i++) arr[i] = i;
            ConcurrentQueue<int> s = new ConcurrentQueue<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[i], 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[i], 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[i], (int)sa3[i]);
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:34,代码来源:ConcurrentQueueTests.cs


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