本文整理汇总了C#中CircularBuffer.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.CopyTo方法的具体用法?C# CircularBuffer.CopyTo怎么用?C# CircularBuffer.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.CopyTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CircularBuffer_CopyTo
public void CircularBuffer_CopyTo()
{
var data = new[] { 12, 4, 9, 43, 0 };
var buffer = new CircularBuffer<int>(10);
buffer.EnqueueRange(data, 0, data.Length);
var dataCopy = new int[5];
buffer.CopyTo(dataCopy, 0, 5);
CollectionAssert.AreEqual(new[] { 12, 4, 9, 43, 0 }, dataCopy);
}
示例2: ShouldSaveWithOverflowArray
public void ShouldSaveWithOverflowArray()
{
var buffer = new CircularBuffer<int>(4);
for(var i = 0; i < 6; i++)
{
buffer.Add(i);
}
var result = new [] { 3, 4, 5 };
var copy = new int[3];
buffer.CopyTo(copy, 0);
Assert.AreEqual(result, copy);
}
示例3: ShouldSaveWithoutOverflowArray
public void ShouldSaveWithoutOverflowArray()
{
var buffer = new CircularBuffer<int>(5);
var array = new [] { 1, 2, 3, -1, 0 };
for(var i = 0; i < 3; i++)
{
buffer.Add(array[i]);
}
var copy = new int[5];
copy[3] = -1;
buffer.CopyTo(copy, 0);
CollectionAssert.AreEqual(array, copy);
}
示例4: CopyToWithIndex_OverCapacity_RetainsOrder
public void CopyToWithIndex_OverCapacity_RetainsOrder()
{
var buffer = new CircularBuffer<int>(3);
buffer.Add(1);
buffer.Add(2);
buffer.Add(3);
buffer.Add(4);
var result = new int[5];
buffer.CopyTo(result, 2);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(0, result[1]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(3, result[3]);
Assert.AreEqual(4, result[4]);
}
示例5: CopyTo_WithinCapacity_OnlyCopiesAddedItems
public void CopyTo_WithinCapacity_OnlyCopiesAddedItems()
{
var buffer = new CircularBuffer<int>(3);
buffer.Add(1);
buffer.Add(2);
var result = new int[2];
buffer.CopyTo(result, 0);
Assert.AreEqual(1, result[0]);
Assert.AreEqual(2, result[1]);
}