C# Queue Tutorial with Examples

C# Queue Tutorial with Examples

Today, We want to share with you C# Queue Tutorial with Examples.
In this post we will show you Queue in C#.Net with example, hear for C# Generic Queue Tutorial with Programming Example we will give you demo and example for implement.
In this post, we will learn about How to use C# Queue Class with an example.

Introduction: Queue in C#.Net with example

In this post, we will learn about Queue in C#.Net with example.Queue follows a first-in, first-out process.

Useful Methods of Queue Class:

Some of the most and useful methods of stack are:

READ :  How to remove multiple comma from string using Angularjs

Enqueue(object obj)

This method adds an object to the end of the Queue.

Dequeue(object obj)

This method removes and returns the object at the beginning of the Queue.

Contains(object obj)

This method determines whether an element is in the Queue.

Clear()

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

This methods removes all elements from the Queue.

object[] ToArray()

This methods copies the Queue to a new array.

TrimToSize()

This method sets the capacity to the actual number of elements in the Queue.

Example

Now, Create one Console Application and write below lines of codes in Visual Studio.

using System;
using System.Collections;

namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Queue Demo code
            Queue _Color = new Queue();

            _Color.Enqueue("Red");   // Adding elements to queue.
            _Color.Enqueue("Green");
            _Color.Enqueue("Blue");

            Console.WriteLine("Current queue: ");
            foreach (string c in _Color) Console.Write(c + " ");

            Console.WriteLine();
            _Color.Enqueue("White");
            Console.WriteLine("Current queue: ");
            foreach (string c in _Color) Console.Write(c + " ");

            Console.WriteLine();
            Console.WriteLine("Removing some values ");
            string s = (string)_Color.Dequeue();
            Console.WriteLine("The removed value: {0}", s);            

            Console.WriteLine("Current queue: ");
            foreach (string c in _Color) Console.Write(c + " ");

            Console.ReadKey();
        }
    }
}

Read :

READ :  Angular Material Carousel Image Sliders - AngularJS Responsive Carousel

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about C# Queue Collection Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.