I'm creating a Dictionary object, using IEnumerable
's ToDictionary()
extension method:
var dictionary = new Dictionary<string, MyType> (myCollection.ToDictionary<MyType, string>(k => k.Key));
When it executes, it throws the following ArgumentException
:
An item with the same key has already been added.
How do I get it to tell me what the duplicate key is?
Get the duplicate keys:
var duplicateKeys = myCollection .GroupBy(k => k.Key) .Where(g => g.Count() > 1) .Select(g => g.Key);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With