 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 StringDictionary to Array at the specified index in C#
To copy StringDictionary to Array at the specified index, the code is as follows −
Example
using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringDictionary strDict = new StringDictionary();       strDict.Add("1", "SUV");       strDict.Add("2", "AUV");       strDict.Add("3", "Electric Car");       strDict.Add("4", "Utility Vehicle");       strDict.Add("5", "Hatchback");       strDict.Add("6", "Compact car");       strDict.Add("7", "MUV");       strDict.Add("8", "Crossover");       strDict.Add("9", "Covertible");       strDict.Add("10", "Quadricycle");       DictionaryEntry[] arr = { new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry()};       strDict.CopyTo(arr, 0);       for (int i = 0; i < arr.Length; i++) {          Console.WriteLine(arr[i].Key + " " + arr[i].Value);       }    } }  Output
This will produce the following output −
10 Quadricycle 1 SUV 2 AUV 3 Electric Car 4 Utility Vehicle 5 Hatchback 6 Compact car 7 MUV 8 Crossover 9 Covertible
Example
Let us now see another example −
using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringDictionary strDict = new StringDictionary();       strDict.Add("1", "SUV");       strDict.Add("2", "AUV");       strDict.Add("3", "Electric Car");       strDict.Add("4", "Utility Vehicle");       strDict.Add("5", "Hatchback");       strDict.Add("6", "Compact car");       DictionaryEntry[] arr = { new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry(),          new DictionaryEntry()};       strDict.CopyTo(arr, 2);       for (int i = 0; i < arr.Length; i++) {          Console.WriteLine(arr[i].Key + " " + arr[i].Value);       }    } }  Output
This will produce the following output−
1 SUV 2 AUV 3 Electric Car 4 Utility Vehicle 5 Hatchback 6 Compact car
Advertisements
 