Solved

Add key and value accordingly in Dictionary c#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
detecting  the added row index in a datagridview 3 60
This code tracks birthdays 3 60
VB.Net How to Exit Sub - Exit Form??? 5 51
Error in JQuery 5 38
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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

25 Experts available now in Live!

Get 1:1 Help Now