
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Add an object to the end of the Queue - Enqueue Operation in C#
To add an object to the end of the Queue, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ Queue<string> queue = new Queue<string>(); queue.Enqueue("Electronics"); queue.Enqueue("Accessories"); queue.Enqueue("Toys"); queue.Enqueue("Books"); queue.Enqueue("Furniture"); queue.Enqueue("Clothing"); queue.Enqueue("Footwear"); queue.Enqueue("Cookware"); queue.Enqueue("Pet Supplies"); Console.WriteLine("Elements in the Queue..."); foreach(var element in queue){ Console.WriteLine(element); } Console.WriteLine("Do the queue has the element Books? = "+queue.Contains("Books")); } }
Output
This will produce the following output −
Elements in the Queue... Electronics Accessories Toys Books Furniture Clothing Footwear Cookware Pet Supplies Do the queue has the element Books? = True
Example
Let us now see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(){ Queue<string> queue = new Queue<string>(); queue.Enqueue("Gary"); queue.Enqueue("Jack"); queue.Enqueue("Ryan"); queue.Enqueue("Kevin"); queue.Enqueue("Mark"); queue.Enqueue("Jack"); queue.Enqueue("Ryan"); queue.Enqueue("Kevin"); Console.Write("Count of elements = "); Console.WriteLine(queue.Count); queue.Clear(); Console.Write("Count of elements (updated) = "); Console.WriteLine(queue.Count); } }
Output
This will produce the following output −
Count of elements = 8 Count of elements (updated) = 0
- Related Articles
- Add an object to the end of Collection in C#
- Add an object to the end of the ArrayList in C#
- Get the object at the beginning of the Queue – Peek Operation in C#
- Enqueue and deque in Queue class in C#
- Add a string to the end of the StringCollection in C#
- Java Menu Driven Program to Perform Queue Operation
- C++ Program to Split the array and add the first part to the end?
- Check if an element is in the Queue in C#
- How to Add Periods to The End of Cell Contents in Excel?
- How to add an object to the canvas using FabricJS?
- Program to design a queue that moves the most recently used element to the end of it in Python
- How to add comma at the end of cell/text in Excel?
- C# Program to skip elements of an array from the end
- Add elements at the end of a Vector in Java
- Add elements to a Queue using Javascript

Advertisements