Why is there no Add method available for Dictionary that takes a KeyValuePair as its parameter?
#45425
Replies: 4 comments
|
I'm trying to define a Dictionary in XAML, but without a So, I'm trying to use KeyValuePair for this. However, since no Add method accepts a KeyValuePair as its argument, I am unable to proceed. |
|
Dictionary<TKey, TValue> has an Add(KeyValuePair<TKey, TValue>) method as an explicit interface implementation for ICollection<KeyValuePair<TKey, TValue>>: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.system-collections-generic-icollection-system-collections-generic-keyvaluepair-tkey-tvalue---add?view=net-9.0#system-collections-generic-dictionary-2-system-collections-generic-icollection((system-collections-generic-keyvaluepair((tkey@tvalue))))-add(system-collections-generic-keyvaluepair((-0-1))) But I don't know whether that can be used in XAML. |
|
Yes, it's implemented explicitly. It's quite unfortunate. |
|
Can you use ResourceDictionary instead? It is not generic though, and it is defined in PresentationFramework.dll rather than System.Xaml.dll, so might not be appropriate if you are using XAML for non-UI purposes. |
Uh oh!
There was an error while loading. Please reload this page.
Why is there no
Addmethod available for Dictionary that takes aKeyValuePairas its parameter?Any specific reason?
All reactions