示例#1
0
        static void Main(string[] args)
        {
            var buffer = new CircularBuffer(capacity: 3);

            while (true)
            {
                var value = 0.0;
                var input = Console.ReadLine();

                if (double.TryParse(input, out value))
                {
                    buffer.Write(value);
                    continue;
                }
                break;
            }

            var sum = 0.0;

            Console.WriteLine("Buffer: ");
            while (!buffer.IsEmpty)
            {
                sum += buffer.Read();
            }
            Console.WriteLine(sum);
        }
示例#2
0
        static void Main(string[] args)
        {
            CircularBuffer buffer = new CircularBuffer(capacity: 3);

            while (true)
            {
                string input = Console.ReadLine();
                byte   value;
                if (byte.TryParse(input, out value))
                {
                    buffer.Write(value);
                }
                else
                {
                    break;
                }
            }

            Console.Write("Buffer: ");
            while (!buffer.IsEmpty)
            {
                byte a = buffer.Read();
                Console.Write(a + " ");
            }


            Console.ReadKey();
        }
示例#3
0
        private static void ProcessInput(CircularBuffer <double> buffer)
        {
            while (true)
            {
                var value = 0.0;
                var input = Console.ReadLine();

                if (double.TryParse(input, out value))
                {
                    buffer.Write(value);
                    continue;
                }
                break;
            }
        }