I am using ASP.NET MVC and I was populating a Dictionary and was getting the An item with the same key has already been added.
error now what I am trying to is if the key already exists in the Dictionary, make it unique by adding a number next to the key name.
if (!RedBlueData.ContainsKey(model))
{
RedBlueData.Add(model, redBlue);
}
else
{
RedBlueData.Add(model, redBlue);
}
The expected result would be (lets say the key string name is "Item" then if there is going to be another key with the name "Item" I would like to name it "Item 2" and if there is a 3rd or 4th have the name as "Item 3" and "Item 4"
I hope this makes sense.