本文整理汇总了C#中CircularBuffer.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.RemoveAt方法的具体用法?C# CircularBuffer.RemoveAt怎么用?C# CircularBuffer.RemoveAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.RemoveAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UsageExample
public void UsageExample()
{
// Create a buffer with a capacity of 5 items.
var buffer = new CircularBuffer<long>(5);
// Add three.
foreach (var i in Enumerable.Range(1, 3))
buffer.Enqueue(i);
Debug.WriteLine(buffer);
// Capacity=5, Count=3, Buffer=[1,2,3]
// Add three more.
foreach (var i in Enumerable.Range(4, 3))
buffer.Enqueue(i);
Debug.WriteLine(buffer);
// Capacity=5, Count=5, Buffer=[2,3,4,5,6]
// Remove the third.
var value = buffer[3];
buffer.RemoveAt(3);
Debug.WriteLine(buffer);
// Capacity=5, Count=4, Buffer=[2,3,4,6]
// Re-insert it.
buffer.Insert(3, value);
Debug.WriteLine(buffer);
// Capacity=5, Count=5, Buffer=[2,3,4,5,6]
// Dequeue.
Debug.Print("Value = {0}", buffer.Dequeue());
// Value = 2
Debug.WriteLine(buffer);
// Capacity=5, Count=4, Buffer=[3,4,5,6]
// Increase the capacity.
buffer.Capacity = 6;
Debug.WriteLine(buffer);
// Capacity=6, Count=4, Buffer=[3,4,5,6]
// Add three more.
foreach (var i in Enumerable.Range(7, 3))
buffer.Enqueue(i);
Debug.WriteLine(buffer);
// Capacity=6, Count=6, Buffer=[4,5,6,7,8,9]
// Reduce the capacity.
buffer.Capacity = 4;
Debug.WriteLine(buffer);
// Capacity=4, Count=4, Buffer=[4,5,6,7]
// Clear the buffer.
buffer.Clear();
Debug.WriteLine(buffer);
// Capacity=4, Count=0, Buffer=[]
}
示例2: TestRemoveAt
public void TestRemoveAt()
{
var buffer = new CircularBuffer<long>(5);
Assert.AreEqual(default(long), buffer.Enqueue(1));
Assert.AreEqual(default(long), buffer.Enqueue(2));
Assert.AreEqual(default(long), buffer.Enqueue(3));
Assert.AreEqual(default(long), buffer.Enqueue(4));
Assert.AreEqual(default(long), buffer.Enqueue(5));
buffer.RemoveAt(buffer.IndexOf(2));
buffer.RemoveAt(buffer.IndexOf(4));
Assert.AreEqual(3, buffer.Count);
Assert.AreEqual(1, buffer.Dequeue());
Assert.AreEqual(3, buffer.Dequeue());
Assert.AreEqual(5, buffer.Dequeue());
Assert.AreEqual(0, buffer.Count);
Assert.AreEqual(default(long), buffer.Enqueue(1));
Assert.AreEqual(default(long), buffer.Enqueue(2));
Assert.AreEqual(default(long), buffer.Enqueue(3));
Assert.AreEqual(default(long), buffer.Enqueue(4));
Assert.AreEqual(default(long), buffer.Enqueue(5));
buffer.RemoveAt(buffer.IndexOf(1));
buffer.RemoveAt(buffer.IndexOf(3));
buffer.RemoveAt(buffer.IndexOf(5));
Assert.AreEqual(2, buffer.Count);
Assert.AreEqual(2, buffer.Dequeue());
Assert.AreEqual(4, buffer.Dequeue());
Assert.AreEqual(0, buffer.Count);
}