123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QueueGenerics { class Program { static void Main(string[] args) { //UseGenericStack(); UseQueue(); Console.ReadLine(); } static void UseQueue() { Queue<Person> queueOfPeople = new Queue<Person>(); queueOfPeople.Enqueue(new Person { Age = 123, FirstName = "123", LastName = "123" }); queueOfPeople.Enqueue(new Person { Age = 1234, FirstName = "1234", LastName = "1234" }); queueOfPeople.Enqueue(new Person { Age = 123, FirstName = "1234", LastName = "1234" }); //first in queue? Console.WriteLine("First is "+queueOfPeople.Peek().FirstName); // do some job with 1-st element in queue Person person = queueOfPeople.Peek(); Console.WriteLine("First is " + person.FirstName); queueOfPeople.Dequeue(); // getting out of queue //next in queue? Console.WriteLine("Next is " + queueOfPeople.Peek().FirstName); } public class Person { public int Age { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Person() { } public Person(int age, string firstName, string lastName) { Age = age; FirstName = firstName; LastName = lastName; } } } |