当前位置: 首页>>代码示例>>C#>>正文


C# CircularBuffer.RemoveAt方法代码示例

本文整理汇总了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=[]
        }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:55,代码来源:CircularBufferFixture.cs

示例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);
 }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:28,代码来源:CircularBufferFixture.cs


注:本文中的CircularBuffer.RemoveAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。