Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to add data to dictionary in C#

1 Answer

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

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

            dic.Add("c", 1);
            dic.Add("c++", 0);
            dic.Add("c#", -1);
            dic.Add("php", 3);
            dic.Add("java", 2);

            foreach (KeyValuePair<string, int> data in dic) {
                Console.WriteLine("Key = {0} : Value = {1}", data.Key, data.Value);
            }
        }
    }
}


/*
run:

Key = c : Value = 1
Key = c++ : Value = 0
Key = c# : Value = -1
Key = php : Value = 3
Key = java : Value = 2

*/

 





answered Aug 3, 2018 by avibootz

Related questions

2 answers 145 views
1 answer 282 views
1 answer 64 views
64 views asked Feb 21, 2017 by avibootz
2 answers 89 views
89 views asked Feb 21, 2017 by avibootz
1 answer 86 views
...