How to initialize a dictionary in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            Dictionary<string, int> dir = new Dictionary<string, int>()
            {
                { "c#", 98 }, { "c++", 99 }, { "php", 100 }
            };

            foreach (KeyValuePair<string, int> kv in dir) {
                Console.WriteLine($"{kv.Key} : {kv.Value}");
            }
        }
    }
}


/*
run:
   
c# : 98
c++ : 99
php : 100
 
*/

 



answered Aug 24, 2018 by avibootz

Related questions

2 answers 119 views
2 answers 159 views
159 views asked Nov 26, 2020 by avibootz
1 answer 157 views
1 answer 143 views
3 answers 156 views
1 answer 147 views
147 views asked Sep 19, 2020 by avibootz
2 answers 230 views
...