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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Yes, it's implemented explicitly. It's quite unfortunate. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Why is there no
Add
method available for Dictionary that takes aKeyValuePair
as its parameter?Any specific reason?
Beta Was this translation helpful? Give feedback.
All reactions