-2

I have

Dictionary idDictionary = new Dictionary();

within this Dictionary, I want, add two row with same key but values different

I used this Dictionary in many methods that a global Dictionary in one method has that issue. if I changed like all u suggest another method get error

malathi
  • 5
  • 7
  • What you need is [`LookUp`](https://msdn.microsoft.com/en-us/library/bb460184(v=vs.100).aspx), try exploring it. – Hari Prasad Jun 10 '16 at 09:48
  • have a look at http://stackoverflow.com/questions/3639972/a-dictionary-with-multiple-entries-with-the-same-key – Justin CI Jun 10 '16 at 09:48
  • There are some ways to do it. But it is important that you must try it yourself first. What have you done so far? – tgpdyk Jun 10 '16 at 09:54

1 Answers1

0

Try something like this.

Dictionary<string, List<string>> obj = new Dictionary<string, List<string>>();

            List<string> keyValue = new List<string>();
            keyValue.Add("a");
            keyValue.Add("b");
            obj.Add("key1", keyValue);

            foreach (KeyValuePair<string, List<string>> entry in obj)
            {
                // do something with entry.Value or entry.Key
            }

            List<string> keyValueOutput = new List<string>();
            if (obj.TryGetValue("key1",out keyValueOutput))
            {
                foreach (string s in keyValueOutput)
                {
                    // do something with entry.Value or entry.Key
                }
            }
Keppy
  • 471
  • 1
  • 7
  • 23
  • I used this Dictionary in many methods that a global Dictionary in one method has that issue. if I changed like all u suggest another method get error – malathi Jun 10 '16 at 11:53
  • That is expected if you want to change the existing Dictionary. – Keppy Jun 13 '16 at 14:21