
- 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
Convert Queue To array in C#
To convert queue to the array, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ Queue<int> queue = new Queue<int>(); queue.Enqueue(100); queue.Enqueue(200); queue.Enqueue(300); queue.Enqueue(400); queue.Enqueue(500); queue.Enqueue(600); queue.Enqueue(700); queue.Enqueue(800); queue.Enqueue(900); queue.Enqueue(1000); Console.WriteLine("Queue..."); foreach(int i in queue){ Console.WriteLine(i); } int[] intArr = queue.ToArray(); Console.WriteLine("Convert Queue to Array..."); foreach(int i in intArr){ Console.WriteLine(i); } } }
Output
This will produce the following output −
Queue... 100 200 300 400 500 600 700 800 900 1000 Convert Queue to Array... 100 200 300 400 500 600 700 800 900 1000
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("A"); queue.Enqueue("B"); queue.Enqueue("C"); queue.Enqueue("D"); queue.Enqueue("E"); queue.Enqueue("F"); Console.WriteLine("Array..."); foreach(string i in queue){ Console.WriteLine(i); } string[] strArr = queue.ToArray(); Console.WriteLine("Convert Queue to Array..."); foreach(string i in strArr){ Console.WriteLine(i); } } }
Output
This will produce the following output −
Array... A B C D E F Convert Queue to Array... A B C D E F
- Related Articles
- Array implementation of queue in C++
- C++ Program to Implement Queue using Array
- Copying the Queue elements to one-dimensional array in C#
- Convert a Queue to a List in Java
- Convert Stack to array in C#
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue) in C++
- Convert string to char array in C++
- Convert a String to Integer Array in C/C++
- How to convert a JavaScript array to C# array?
- C# Program to convert integer array to string array
- Difference Between Array-Based Queue and List-Based Queue
- queue::front() and queue::back() in C++ STL
- queue::empty() and queue::size() in C++ STL
- queue::push() and queue::pop() in C++ STL
- How to convert string to char array in C++?

Advertisements