[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Add key and value accordingly in Dictionary c#

Posted on 2010-11-14
2
Medium Priority
?
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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