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


C# ObservableCollection.CopyTo方法代码示例

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


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

示例1: CopyToTest_Negative

        public static void CopyToTest_Negative()
        {
            string[] anArray = new string[] { "one", "two", "three", "four" };
            ObservableCollection<string> collection = new ObservableCollection<string>(anArray);

            int[] iArrInvalidValues = new Int32[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue };
            foreach (var index in iArrInvalidValues)
            {
                string[] aCopy = new string[collection.Count];
                Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(aCopy, index));
            }

            int[] iArrLargeValues = new Int32[] { collection.Count, Int32.MaxValue, Int32.MaxValue / 2, Int32.MaxValue / 10 };
            foreach (var index in iArrLargeValues)
            {
                string[] aCopy = new string[collection.Count];
                Assert.Throws<ArgumentException>(() => collection.CopyTo(aCopy, index));
            }

            Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 1));

            string[] copy = new string[collection.Count - 1];
            Assert.Throws<ArgumentException>(() => collection.CopyTo(copy, 0));

            copy = new string[0];
            Assert.Throws<ArgumentException>(() => collection.CopyTo(copy, 0));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:27,代码来源:ObservableCollection_MethodsTest.cs

示例2: DeleteSuiteObservableCollection

        /// <summary>
        /// Deletes the suite from the suite observable collection.
        /// </summary>
        /// <param name="suites">The suites.</param>
        /// <param name="suiteForDeleteId">The suite for delete unique identifier.</param>
        public void DeleteSuiteObservableCollection(ObservableCollection<Suite> suites, int suiteForDeleteId)
        {
            Suite[] suitesCopy = new Suite[suites.Count];
            suites.CopyTo(suitesCopy, 0);

            for (int i = 0; i < suitesCopy.Length; i++)
            {
                if (suitesCopy[i].Id.Equals(suiteForDeleteId) && suitesCopy[i].Parent != null)
                {
                    suitesCopy[i].Parent.SubSuites.Remove(suitesCopy[i]);
                }
                if (suitesCopy[i].SubSuites != null && suitesCopy[i].SubSuites.Count > 0)
                {
                    this.DeleteSuiteObservableCollection(suitesCopy[i].SubSuites, suiteForDeleteId);
                }
            }
        }
开发者ID:ypupo2002,项目名称:tfs-testcasemanager,代码行数:22,代码来源:TestCasesInitialViewModel.cs

示例3: CopyToTest

        public static void CopyToTest()
        {
            string[] anArray = new string[] { "one", "two", "three", "four" };
            ObservableCollection<string> collection = new ObservableCollection<string>((IEnumerable<string>)anArray);

            string[] aCopy = new string[collection.Count];
            collection.CopyTo(aCopy, 0);
            for (int i = 0; i < anArray.Length; ++i)
                Assert.Equal(anArray[i], aCopy[i]);

            // copy observable collection starting in middle, where array is larger than source.
            aCopy = new string[collection.Count + 2];
            int offsetIndex = 1;
            collection.CopyTo(aCopy, offsetIndex);
            for (int i = 0; i < aCopy.Length; i++)
            {
                string value = aCopy[i];
                if (i == 0)
                    Assert.True(null == value, "Should not have a value since we did not start copying there.");
                else if (i == (aCopy.Length - 1))
                    Assert.True(null == value, "Should not have a value since the collection is shorter than the copy array..");
                else
                {
                    int indexInCollection = i - offsetIndex;
                    Assert.Equal(collection[indexInCollection], aCopy[i]);
                }
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:28,代码来源:ObservableCollection_MethodsTest.cs


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