Esempio n. 1
0
        static void Main(string[] args)
        {
            var stack = new ConcurrentStack <int>();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);

            if (stack.TryPeek(out int result))
            {
                Console.WriteLine($"{result} is on top");
            }

            if (stack.TryPop(out result))
            {
                Console.WriteLine($"Popped {result}");
            }

            var items = new int[5];

            if (stack.TryPopRange(items, 0, 5) > 0)
            {
                var text = string.Join(", ", items.Select(i => i.ToString()));
                Console.WriteLine($"Popped items : {text}");
            }

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            ConcurrentStack <int> stack = new ConcurrentStack <int>();

            stack.Push(42);

            int result;

            if (stack.TryPop(out result))
            {
                Console.WriteLine($"Popped: {result}");
            }
            stack.PushRange(new int[] { 1, 2, 3 });
            int[] values = new int[3];
            stack.TryPopRange(values);

            foreach (var item in values)
            {
                Console.WriteLine(item);
            }
        }