本文整理汇总了C#中CircularBuffer.Read方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Read方法的具体用法?C# CircularBuffer.Read怎么用?C# CircularBuffer.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCircularBuffer_2
public void TestCircularBuffer_2()
{
var cb = new CircularBuffer<int>(3);
Assert.Equal(0, cb.Read(new int[10], 0, 10));
cb.Write(new[] { 1, 2 });
Assert.Equal(new[] { 1, 2 }, Read(cb, 2));
cb.Write(new[] { 3, 4 });
Assert.Equal(new[] { 3, 4 }, Read(cb, 2));
}
示例2: Read
private static int[] Read(CircularBuffer<int> cb, int count)
{
var buffer = new int[count];
int read = 0;
while (read < count)
{
read += cb.Read(buffer, read, count - read);
}
return buffer;
}
示例3: TestCircularBuffer
public void TestCircularBuffer()
{
var cb = new CircularBuffer<int>(2);
Assert.Throws<InvalidOperationException>(() => cb.Read());
cb.Write(1);
Assert.Equal(1, cb.Read());
cb.Write(2);
cb.Write(3);
Assert.Equal(2, cb.Read());
cb.Write(4);
Assert.Equal(new[] { 3, 4 }, Read(cb, 2));
cb.Write(new[] { 5, 6, 7, 8, 9 });
Assert.Equal(new[] { 5, 6, 7 }, Read(cb, 3));
cb.Write(new[] { 10, 11 });
Assert.Equal(8, cb.Read());
cb.Write(new[] { 12, 13, 14, 15, 16, 17 });
Assert.Equal(new[] { 9, 10, 11 }, Read(cb, 3));
Assert.Equal(new[] { 12, 13, 14, 15, 16, 17 }, Read(cb, 6));
}