?
Solved

Add key and value accordingly in Dictionary c#

Posted on 2010-11-14
2
Medium Priority
?
364 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 2000 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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

850 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