I can’t have the same key. But a simple (and effective) solution is put a suffix after key.
But as I’m in a foreach, I was wondering a fast and clean way to add a number suffix to duplicated keys.
e.g.:
My foreach is that:
foreach (Item item in items) {
dic.Add(item.SomeKey, item.SomeValue);
}
But I don’t want duplicated keys, so I need to ‘handle’ SomeKey to Origin become Result
SomeKey Origin: key, clave, clave, chave, chave, chave
SomeKey Result: key, clave, clave1, chave, chave1, chave2
Edit:
My answer to @KooKiz explain better the question.
I have few duplicated entries. I’m just trying to figure out how to then increment the suffix until you find no item. Sounds like reinvent wheels, so I was wondering if someone know a good way to do that
That may not be the fastest, but that’s the more readable I can think of: