Adding objects to a queue in c#

Person Class:

public class person
{
    string firstName;
    string lastName;
    public person(string _firstName, string _lastName)
    {
        firstName = _firstName;
        lastName = _lastName;
    }
    override public string ToString()
    {
        return firstName + " " + lastName;
    }
}

adding the person class object to a queue

Queue<person> q = new Queue<person>();
q.Enqueue(new person("p1fn", "p1ln"));
q.Enqueue(new person("p2fn", "p2ln"));
q.Enqueue(new person("p3fn", "p3ln"));
Console.WriteLine("Queue demonstration:");
for (int i = 1; i <= 3; i++)
Console.WriteLine(q.Dequeue().ToString());

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.