How to convert dictionary to list in c#.net

Using below example we can convert the dictionary to list in c#.net

        static void Main(string[] args)
        {
            //convert dictionary to list
            Dictionary<int, string> empDictionary = new Dictionary<int, string>();
            empDictionary[1] = "Ranga";
            empDictionary[2] = "Rajesh";

            //convert dictionary to list
            List<KeyValuePair<int, string>> empList = new List<KeyValuePair<int, string>>();
            empList = empDictionary.ToList();

            foreach(var data in empList)
            {
                Console.Write("key:"+ data.Key);
                Console.WriteLine("   value:"+data.Value);
            }

            Console.Read();
        }


output:


If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar