

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Copy the entire LinkedList to Array in C#
To copy the entire LinkedList to Array, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<int> list = new LinkedList<int>(); list.AddLast(100); list.AddLast(200); list.AddLast(300); int[] strArr = new int[5]; list.CopyTo(strArr, 0); foreach(int str in strArr){ Console.WriteLine(str); } } }
Output
This will produce the following output −
100 200 300 0 0
Example
Let us now see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<int> list = new LinkedList<int>(); list.AddLast(100); list.AddLast(200); list.AddLast(300); int[] strArr = new int[10]; list.CopyTo(strArr, 4); foreach(int str in strArr){ Console.WriteLine(str); } } }
Output
This will produce the following output −
0 0 0 0 100 200 300 0 0 0
- Related Questions & Answers
- How to copy the entire ArrayList to a one-dimensional Array in C# ?
- How to Copy the entire contents of a directory in C#?
- Array Copy in C#
- Copy the Stack to an Array in C#
- How to image copy the entire DB2 table TAB1 into a dataset?
- Copy StringDictionary to Array at the specified index in C#
- LinkedList in C#
- How to copy collection to Array using C#?
- Convert LinkedList to an array in Java
- How to use the Copy(, ,) method of array class in C#
- Copy ListDictionary to Array instance at the specified index in C#
- How to convert LinkedList to Array in Java?
- Copying the entire ArrayList to 1-D Array starting at the specified index in C#
- Copy StringCollection at the specified index of array in C#
- Copy OrderedDictionary elements to Array instance at the specified index in C#
Advertisements