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


C# ReadOnlyList.CopyTo方法代码示例

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


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

示例1: Test

		public void Test()
		{
			List<string> strings = new List<string>(new string[] { "a", "b", "c" });
			ReadOnlyList<String> read = new ReadOnlyList<string>(strings);
			strings.Add("d");
			Assert.AreEqual(3, read.Count);
			Assert.IsTrue(read.Contains("a"));
			Assert.AreEqual(0, read.IndexOf("a"));
			Assert.IsTrue(read.Contains("b"));
			Assert.AreEqual(1, read.IndexOf("b"));
			Assert.IsTrue(read.Contains("c"));
			Assert.AreEqual(2, read.IndexOf("c"));
			Assert.IsFalse(read.Contains("d"));
			Assert.AreEqual(-1, read.IndexOf("d"));
			Assert.AreEqual("a,b,c", String.Join(",", read.ToArray()));
			Assert.AreEqual("a,b,c", String.Join(",", new List<String>(read).ToArray()));
			
			string[] arcopy = new string[3];
			read.CopyTo(arcopy, 0);
			Assert.AreEqual("a,b,c", String.Join(",", arcopy));

			System.Collections.IEnumerator en = ((System.Collections.IEnumerable)read).GetEnumerator();
			Assert.IsTrue(en.MoveNext());
			Assert.AreEqual("a", en.Current);
			Assert.IsTrue(en.MoveNext());
			Assert.AreEqual("b", en.Current);
			Assert.IsTrue(en.MoveNext());
			Assert.AreEqual("c", en.Current);
			Assert.IsFalse(en.MoveNext());
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:30,代码来源:TestReadOnlyList.cs

示例2: TestCopyToArray

    public void TestCopyToArray() {
      int[] inputIntegers = new int[] { 12, 34, 56, 78 };
      ReadOnlyList<int> testList = new ReadOnlyList<int>(inputIntegers);

      int[] outputIntegers = new int[testList.Count];
      testList.CopyTo(outputIntegers, 0);

      CollectionAssert.AreEqual(inputIntegers, outputIntegers);
    }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:9,代码来源:ReadOnlyList.Test.cs

示例3: TestICollection

        public void TestICollection()
        {
            ICollection read = new ReadOnlyList<int>((IEnumerable<int>)new int[] { 5, 10, 15 });
            Assert.AreEqual(3, read.Count);
            Assert.IsFalse(read.IsSynchronized);
            Assert.IsTrue(Object.ReferenceEquals(read, read.SyncRoot));

            long[] lary = new long[3];
            read.CopyTo(lary, 0);
            Assert.AreEqual(5L, lary[0]);
            Assert.AreEqual(10L, lary[1]);
            Assert.AreEqual(15L, lary[2]);

            ICollection copy = (ICollection)((ICloneable)read).Clone();
            Assert.AreEqual(3, copy.Count);
        }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:16,代码来源:TestReadOnlyList.cs


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