Solved

Add key and value accordingly in Dictionary c#

Posted on 2010-11-14
2
339 Views
Last Modified: 2012-05-10
try to make the dict collections output appear as

A 1
B 2
C 2

current display is :
A 1
B 1
C 1
static void Main(string[] args)
        {
            string[] strArray = { "A", "B", "C" };
            int[] intArray = { 1, 2, 3 };

            Dictionary<string, int> dict = new Dictionary<string, int>();

            foreach (string strArray01 in strArray)
            {
                foreach (int intArra01 in intArray)
                {
                    dict.Add(strArray01, intArra01);
                    
                    break;

                }

            }

            foreach (KeyValuePair<string, int> kv in dict)
            {

                Console.WriteLine("Key : {0}, Value : {1}", kv.Key, kv.Value);

            }

            Console.ReadLine();

        }

Open in new window

0
Comment
Question by:doramail05
2 Comments
 
LVL 10

Accepted Solution

by:
hosneylk earned 500 total points
ID: 34133573

for(int i=0; i<3; i++)
            {
                    dict.Add(strArray[i], intArray[i]);
            }

Open in new window

0
 
LVL 1

Author Comment

by:doramail05
ID: 34133764
ok

for (int i = 0; i < strArray.Length; i++)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question