
- 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
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
- Related Articles
- Copy ListDictionary to Array instance 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#
- Gets or sets the value at the specified key in StringDictionary in C#
- Copying the entire ArrayList to 1-D Array starting at the specified index in C#
- Insert at the specified index in StringCollection in C#
- Golang Program to insert an element into the array at the specified index
- Remove entry with specified key from the StringDictionary in C#
- Remove the entry at specified index from OrderedDictionary in C#
- Remove element at specified index of Collection in C#
- Java Program to copy an array from the specified source array
- Remove the element at the specified index of the ArrayList in C#
- Get or Set at specified index in StringCollection in C#
- Insert an element into the ArrayList at the specified index in C#
- Get or set the element at specified index in Collection in C#

Advertisements