How to copy dictionary keys to a list in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    static class Program
    {
        static void Main()
        {
            var dic = new Dictionary<string, int>();
            dic.Add("vb.net", 9);
            dic.Add("java", 6);
            dic.Add("php", 7);
            dic.Add("python", 3);
            dic.Add("c#", 4);

            var keys = new List<string>(dic.Keys);

            foreach (string s in keys)
                Console.WriteLine(s);
        }
    }
}


/*
run:
   
vb.net
java
php
python
c#
    
*/

 



answered Oct 17, 2018 by avibootz

Related questions

1 answer 179 views
1 answer 194 views
1 answer 158 views
1 answer 208 views
1 answer 167 views
167 views asked Aug 3, 2018 by avibootz
2 answers 233 views
...