How would I iterate through the keys and values of an IDictionary
if I don't know the concrete types of the keys and values within, therefore want to just treat them as object
s?
If I do something like:
foreach(var x in myIDictionary) { ... }
I think x
is an object
. But how would I get the Key
and Value
out of it (both typed as object
s), as specified in the IDictionaryEnumerator
? There isn't an IKeyValuePair
without generic parameters is there?
I guess I could loop through the enumerator by hand using MoveNext
etc, but I feel like there must be a way to do it with foreach
!
I think x is an object
Why don't you check what it actually is, rather than just guessing. – Alyssaalyssumx
is before coming here to ask us. – Irritatex
is not "object" though. – AlyssaalyssumIDictionaryEnumerator.Current
, but is that correct? (I did bother to try - otherwise I wouldn't be on StackOverflow in the first place.) – DnieperDictionaryEntry
, but not always"). But feel free to point me in the direction of a documentation that clearly gives a definitive answer. – DnieperIDictionary
on your own. You don't need me (or other answerers) to find it for you. – Alyssaalyssum