Featured post

How to start a programming

Hello everyone! The objective of this post is how to get started with programming. But first I discuss why we learn programming. So, the...

Wednesday, 11 October 2017

How to use Ordered Dictionary C#

Ordered Dictionary

If we need to save data in key pair representation then Ordered Dictionary is best.
Ordered Dictionary represent collection of key pair value and it can be access through key and index.

How to use

1. Create console application in visual studio 2013
2. Use namespace

using System.Collections;
using System.Collections.Specialized

3. Create instance of Ordered Dictionary

OrderedDictionary order = new OrderedDictionary();

4. Add key pair values

order.Add("Name","Salman Mushtaq"); // first argument is key and second argument is value
order.Add("Age","27");
order.Add("Address","Rahim Yar Khan, Pakistan");

5. Add keys and values in Collection

ICollection keyCollections = order.keys;
ICollection valueCollections = order.Values;

6. Copy the keys and values to array so that it will accessable

String[] myKeys = new String[order.Count];
String[] myValues = new String[order.Count];

keyCollections.CopyTo(myKeys,0);
valueCollections.CopyTo(myValues,0);

7. Display keys and values

for(int i=0; i<order.Count; i++)
{
Console.WriteLine("Key: " + myKeys[i] + "   Value: " + myValues[i]);
}

Console.ReadKey();

8. The output is like


Video Demo



Thank you.











1 comment:

Earn money with Payza