- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Copying the Queue elements to one-dimensional array in C#
Queue<T>.CopyTo(T[], Int32) Method is used to copy the Queue elements to a 1-D array.
Example
Let us now see an example −
using System; using System.Collections.Generic; public class Demo{ public static void Main(){ Queue<string> queue = new Queue<string>(); queue.Enqueue("K"); queue.Enqueue("T"); String[] strArr = new String[4]; strArr[0] = "One"; strArr[1] = "Two"; strArr[2] = "Three"; strArr[3] = "Four"; Console.WriteLine("
Array elements: "); for (int i = 0; i < strArr.Length; i++){ Console.WriteLine(strArr[i]); } queue.CopyTo(strArr, 2); Console.WriteLine("
After copying array contains: "); for (int i = 0; i < strArr.Length; i++){ Console.WriteLine("arr[{0}] : {1}", i, strArr[i]); } } }
Output
This will produce the following output −
One Two Three Four After copying array contains: arr[0] : One arr[1] : Two arr[2] : K arr[3] : T
- Related Articles
- Copying the Collection elements to an array in C#
- Copying BitArray elements to an Array in C#
- Copying the Hashtable elements to an Array Instance in C#
- Copying the SortedList elements to an Array Object in C#
- Copying the elements of ArrayList to a new array in C#
- How to access elements from multi-dimensional array in C#?
- Split one-dimensional array into two-dimensional array JavaScript
- How to copy the entire ArrayList to a one-dimensional Array in C# ?
- What is a one-dimensional array in C language?
- Explain pointers and one-dimensional array in C language
- Copying the HybridDictionary entries to an Array Instance in C#
- How do we access elements from the two-dimensional array in C#?
- Convert Queue To array in C#
- How to print one dimensional array in reverse order?
- Dimensional Array in C#?

Advertisements