Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Iterate(CreateQueue(), "queue");
- Iterate(CreateStack(), "stack");
- Console.ReadKey();
- }
- private static IEnumerable<int> CreateQueue()
- {
- var collection = new Queue<int>();
- for (int i = 0; i < 4; i++)
- collection.Enqueue(i);
- return collection;
- }
- private static IEnumerable<int> CreateStack()
- {
- var collection = new Stack<int>();
- for (int i = 0; i < 4; i++)
- collection.Push(i);
- return collection;
- }
- private static void Iterate(IEnumerable<int> collection, string name)
- {
- Console.Write($"{name} foreach: ");
- foreach (var entry in collection)
- Console.Write($"{entry} ");
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement