-1

I want to append a string value in my dictionary in .net however I couldn't find an information about it for .net. Here is my dictionary which is set already with key-value pairs:

Dictionary<int, string> mydict = new Dictionary<int, string>();

I want to append new strings into existing ones in values.

For example: If we have <1,A> pair I want to append it to <1,AB>. Does anybody know a way to do this?

B B
  • 121
  • 9

1 Answers1

1

Well I am not sure what you trying to do, but let me guess: if you have key which exists, you want to append to the corresponding value, if not, insert new key-value pair? If so, see code bloew:

var key = 1;
var val = "new value to append";
if (myDict.CotainsKey(key))
{
    myDict[key] += val;
}
else
{
    myDict.Add(key, val);
}
Joel
  • 5,732
  • 4
  • 37
  • 65
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69