- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
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
Advertisements
To Continue Learning Please Login
Login with Google