How to Access Data From Ordered Dictionary using C#

Category > CSHARP || Published on : Friday, October 27, 2017 || Views: 9013 || Access Data From Ordered Dictionary using C# Ordered Dictionary


Introduction

Here Pawan Kumar will explain How to Access Data From Ordered Dictionary using C#

Description

In previous post I have explained ASP.Net: Call JavaScript function when RadioButton is checked or unchecked, How to Call JavaScript function when CheckBoxList is clicked (checked or unchecked) in ASP.NET, jQuery: Call function when CheckBox is checked or unchecked, How to Implement Reorder List (Drag and Drop) using jQuery in ASP.Net, How To Export HTML Table To Excel Using jQuery Plugin, How to Display Decimal Numbers As Money using Transact-SQL, and many more articles.

Now I will explain How to How to Access Data From Ordered Dictionary using C#

So follow the steps to learn How to Access Data From Ordered Dictionary using C#

Note: We are creating a console application using C#

Step 1: Create a console application project using Visual Studio.

File > New > Project

Step 2: Goto  Visual C# > Windows and then select Console Application and Press enter

Step 3: Add below namespaces

    using System.Collections.Specialized;  
    using System.Collections;  

Step 4: Add the below codes which will create OrderedDictionary

OrderedDictionary person = new OrderedDictionary();
            person.Add("Name", "Ram");
            person.Add("Address", "India");

Step 5:Below is the codes to retrieve the data          

 ICollection keyCOllection = person.Keys;
            ICollection valueCollection = person.Values;

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

            keyCOllection.CopyTo(myKeys, 0);
            valueCollection.CopyTo(myValues, 0);

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

Step 6: Complete Source Codes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Specialized;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            OrderedDictionary person = new OrderedDictionary();
            person.Add("Name", "Ram");
            person.Add("Address", "India");


            ICollection keyCOllection = person.Keys;
            ICollection valueCollection = person.Values;

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

            keyCOllection.CopyTo(myKeys, 0);
            valueCollection.CopyTo(myValues, 0);

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

 

 

Conclusion:

So, In this tutorial we have learned, How to Access Data From Ordered Dictionary using C#