How to get a list of all the 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<int, string>();

            dic.Add(2, "c");
            dic.Add(5, "c++");
            dic.Add(8, "c#");

            List<int> keys = new List<int>(dic.Keys);
            foreach (int key in keys) {
                Console.WriteLine(key);
            }
        }
    }
}


/*
run:
      
2
5
8
  
*/

 



answered Aug 4, 2018 by avibootz

Related questions

1 answer 206 views
1 answer 196 views
196 views asked Oct 17, 2018 by avibootz
1 answer 178 views
1 answer 181 views
181 views asked Aug 3, 2018 by avibootz
1 answer 230 views
2 answers 255 views
...