How to get dictionary keys in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var dic = new Dictionary<string, string>();

            dic.Add("c", "c programming");
            dic.Add("c++", "c++ programming");
            dic.Add("c#", "c# programming");

            List<string> list = new List<string>(dic.Keys);
            foreach (string key in list) {
                Console.WriteLine("{0}", key);
            }
        }
    }
}


/*
run:

c
c++
c#

*/

 



answered Aug 3, 2018 by avibootz

Related questions

1 answer 179 views
1 answer 194 views
1 answer 176 views
176 views asked Oct 17, 2018 by avibootz
1 answer 208 views
2 answers 233 views
1 answer 121 views
121 views asked Mar 6, 2017 by avibootz
...