

- 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
Copying the HybridDictionary entries to an Array Instance in C#
To copy the HybridDictionary entries to an Array Instance, the code is as follows −
Example
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ HybridDictionary dict = new HybridDictionary(); dict.Add("1", "SUV"); dict.Add("2", "AUV"); dict.Add("3", "Utility Vehicle"); dict.Add("4", "MUV"); dict.Add("5", "Compact Car"); dict.Add("6", "Convertible"); Console.WriteLine("HybridDictionary Key and Value pairs..."); foreach(DictionaryEntry entry in dict){ Console.WriteLine("{0} and {1} ", entry.Key, entry.Value); } DictionaryEntry[] dictArr = new DictionaryEntry[10]; Console.WriteLine("\nCopied to Array Instance..."); dict.CopyTo(dictArr, 2); for (int i = 0; i < dictArr.Length; i++) Console.WriteLine("Key = "+dictArr[i].Key + ", Value = " + dictArr[i].Value); } }
Output
This will produce the following output −
HybridDictionary Key and Value pairs... 1 and SUV 2 and AUV 3 and Utility Vehicle 4 and MUV 5 and Compact Car 6 and Convertible Copied to Array Instance... Key = , Value = Key = , Value = Key = 1, Value = SUV Key = 2, Value = AUV Key = 3, Value = Utility Vehicle Key = 4, Value = MUV Key = 5, Value = Compact Car Key = 6, Value = Convertible Key = , Value = Key = , Value =
Example
Let us now see another example −
using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ HybridDictionary dict = new HybridDictionary(10); dict.Add("1", "SUV"); dict.Add("2", "AUV"); dict.Add("3", "Utility Vehicle"); dict.Add("4", "MUV"); Console.WriteLine("HybridDictionary Key and Value pairs..."); foreach(DictionaryEntry entry in dict){ Console.WriteLine("{0} and {1} ", entry.Key, entry.Value); } DictionaryEntry[] dictArr = new DictionaryEntry[10]; Console.WriteLine("\nCopied to Array Instance..."); dict.CopyTo(dictArr, 0); for (int i = 0; i < dictArr.Length; i++) Console.WriteLine("Key = "+dictArr[i].Key + ", Value = " + dictArr[i].Value); } }
Output
This will produce the following output −
HybridDictionary Key and Value pairs... 1 and SUV 2 and AUV 3 and Utility Vehicle 4 and MUV Copied to Array Instance... Key = 1, Value = SUV Key = 2, Value = AUV Key = 3, Value = Utility Vehicle Key = 4, Value = MUV Key = , Value = Key = , Value = Key = , Value = Key = , Value = Key = , Value = Key = , Value =
- Related Questions & Answers
- Copying the Hashtable elements to an Array Instance in C#
- Removing all entries from HybridDictionary in C#
- Copying the Collection elements to an array in C#
- Copying BitArray elements to an Array in C#
- Copying the SortedList elements to an Array Object in C#
- What are the different ways of copying an array into another array in Java?
- Copying the Queue elements to one-dimensional array in C#
- Copying the elements of ArrayList to a new array in C#
- Get an ICollection containing the keys in HybridDictionary in C#
- Get an ICollection containing the values in HybridDictionary in C#
- Using recursion to remove consecutive duplicate entries from an array - JavaScript
- Using recursion to remove consecutive duplicate entries from an array in JavaScript
- Get an enumerator that iterates through the HybridDictionary in C#
- Create new instance of an Array with Java Reflection Method
- Split array entries to form object in JavaScript
Advertisements