本文整理汇总了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());
}
示例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);
}
示例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);
}