Solved

Add key and value accordingly in Dictionary c#

Posted on 2010-11-14
2
310 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now