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


C# CircularBuffer.ToArray方法代码示例

本文整理汇总了C#中CircularBuffer.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.ToArray方法的具体用法?C# CircularBuffer.ToArray怎么用?C# CircularBuffer.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CircularBuffer的用法示例。


在下文中一共展示了CircularBuffer.ToArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CircularBuffer_Enqueue

        public void CircularBuffer_Enqueue()
        {
            var buffer = new CircularBuffer<string>(10);
            buffer.Enqueue("test");
            buffer.Enqueue("string");

            CollectionAssert.AreEqual(new[] { "test", "string" }, buffer.ToArray());
            Assert.AreEqual(2, buffer.Count);
            Assert.AreEqual(10, buffer.Capacity);
            Assert.AreEqual(0, buffer.Head);
            Assert.AreEqual(2, buffer.Tail);
            Assert.IsTrue(buffer.Contains("string"));
            Assert.IsFalse(buffer.Contains("other string"));
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:14,代码来源:CircularBufferTest.cs

示例2: CircularBuffer_Dequeue

        public void CircularBuffer_Dequeue()
        {
            int[] data = { 0, 1, 2, 3 };
            var buffer = new CircularBuffer<int>(data.Length);
            buffer.EnqueueRange(data, 0, data.Length);

            buffer.Dequeue();

            Assert.AreEqual(3, buffer.Count);
            Assert.AreEqual(data.Length, buffer.Capacity);
            Assert.AreEqual(1, buffer.Head);
            Assert.AreEqual(0, buffer.Tail);
            Assert.IsTrue(buffer.Contains(1));
            Assert.IsFalse(buffer.Contains(0));
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, buffer.ToArray());
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:16,代码来源:CircularBufferTest.cs

示例3: CircularBuffer_EnqueueOverwriteAllowed

        public void CircularBuffer_EnqueueOverwriteAllowed()
        {
            string[] data = { "a", "b", "c", "d" };
            var buffer = new CircularBuffer<string>(data.Length);
            buffer.EnqueueRange(data, 0, data.Length);

            buffer.Enqueue("z");

            CollectionAssert.AreEqual(new[] { "z", "b", "c", "d" }, buffer.ToArray());
            Assert.AreEqual(data.Length, buffer.Count);
            Assert.AreEqual(data.Length, buffer.Capacity);
            Assert.AreEqual(0, buffer.Head);
            Assert.AreEqual(1, buffer.Tail);
            Assert.IsTrue(buffer.Contains("z"));
            Assert.IsFalse(buffer.Contains("a"));
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:16,代码来源:CircularBufferTest.cs

示例4: CircularBuffer_EnqueueAfterTrimExcess

        public void CircularBuffer_EnqueueAfterTrimExcess()
        {
            var buffer = new CircularBuffer<string>(10);
            buffer.EnqueueRange(new[] { "a", "b", "c" }, 0, 3);

            buffer.TrimExcess();
            buffer.Enqueue("z");

            CollectionAssert.AreEqual(new[] { "z", "b", "c" }, buffer.ToArray());
            Assert.AreEqual(3, buffer.Count);
            Assert.AreEqual(3, buffer.Capacity);
            Assert.AreEqual(0, buffer.Head);
            Assert.AreEqual(1, buffer.Tail);
            Assert.IsTrue(buffer.Contains("z"));
            Assert.IsFalse(buffer.Contains("a"));
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:16,代码来源:CircularBufferTest.cs

示例5: Deserialize

        protected override Packet Deserialize(CircularBuffer<byte> buffer)
        {
            var parsed = parser.Execute(new ArraySegment<byte>(buffer.ToArray()));
            buffer.Skip(parsed);

            if (processed.Count > 0)
            {
                var data = processed.Dequeue();
                
                var id = Int32.Parse(data["packetId"]);
                
                var type = Packet.GetTypeById(id);

                if (type == null)
                    return null;

                var packet = Activator.CreateInstance(type);

                if (packet == null)
                    Console.WriteLine("packet is null");

                foreach(var field in data)
                {
                    var dest = type.GetField(field.Key);
                    var value = Convert.ChangeType(field.Value, dest.FieldType);
                    
                    dest.SetValue(packet, value);
                }

                Console.WriteLine(packet.GetType());

                return (Packet)packet;
            }
            else
                return null;
        }
开发者ID:pjc0247,项目名称:Merona.Http.cs,代码行数:36,代码来源:Program.cs

示例6: Add_ToArray_ProperlyWorks

            public void Add_ToArray_ProperlyWorks()
            {
                var buffer = new CircularBuffer<int>(3);
                buffer.Add(1);
                buffer.Add(2);
                buffer.Add(3);
                buffer.Add(4);
                buffer.Add(5);
                buffer.Add(6);
                buffer.Add(7);
                buffer.Add(8);

                var result = buffer.ToArray();

                Assert.AreEqual(3, result.Length);
                Assert.AreEqual(6, result.Skip(0).First());
                Assert.AreEqual(7, result.Skip(1).First());
                Assert.AreEqual(8, result.Skip(2).First());
            }
开发者ID:EliSchleifer,项目名称:mstum.utils,代码行数:19,代码来源:CircularBufferTests.cs


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