Link to home
Create AccountLog in
Avatar of doramail05
doramail05Flag for Malaysia

asked on

Add key and value accordingly in Dictionary c#

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

ASKER CERTIFIED SOLUTION
Avatar of hosneylk
hosneylk
Flag of Singapore image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of doramail05

ASKER

ok

for (int i = 0; i < strArray.Length; i++)