本文整理汇总了C#中ReadOnlyCollection.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyCollection.CopyTo方法的具体用法?C# ReadOnlyCollection.CopyTo怎么用?C# ReadOnlyCollection.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyCollection
的用法示例。
在下文中一共展示了ReadOnlyCollection.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCopyToArray
public void TestCopyToArray() {
int[] inputIntegers = new int[] { 12, 34, 56, 78 };
ReadOnlyCollection<int> testCollection = new ReadOnlyCollection<int>(inputIntegers);
int[] outputIntegers = new int[testCollection.Count];
testCollection.CopyTo(outputIntegers, 0);
CollectionAssert.AreEqual(inputIntegers, outputIntegers);
}
示例2: TestCollection
public void TestCollection()
{
// Default ctor.
var data = Enumerable.Range(1, 5).ToArray();
var col = new ReadOnlyCollection<int>(data);
Assert.AreEqual(5, col.Count);
Assert.IsTrue(col.IsReadOnly);
CollectionAssert.AreEqual(data, col);
Assert.IsTrue(col.GetEnumerator().MoveNext());
Assert.IsTrue(((IEnumerable) col).GetEnumerator().MoveNext());
Assert.IsTrue(col.Contains(4));
var arr = new int[5];
col.CopyTo(arr, 0);
CollectionAssert.AreEqual(data, arr);
Assert.Throws<NotSupportedException>(() => col.Add(1));
Assert.Throws<NotSupportedException>(() => col.Clear());
Assert.Throws<NotSupportedException>(() => col.Remove(1));
}
示例3: ReadOnlySet_copyTo
public void ReadOnlySet_copyTo()
{
List<Int32> source = new List<Int32>() { 1, 2, 1, 3 };
ReadOnlyCollection<Int32> actual = new ReadOnlyCollection<int>( source );
Int32[] array = new Int32[ source.Count ];
actual.CopyTo( array, 0 );
for( Int32 i = 0; i < source.Count; i++ )
{
Assert.AreEqual<Int32>( source[ i ], array[ i ] );
}
}