Solved

Add key and value accordingly in Dictionary c#

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i get the executable application's path in a specific form? ('\\' instead of '\ ') 5 39
Wav problem 4 26
C# guarantee sql connection close 6 39
Printing 1 51
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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