Feedback
Preserve dictionary key and value types when iterating KeyValuePair entries
- Status
- Fixed
- Fixed in
- v26.6.2
- Source discussion
- https://forum.objo.dev/d/281-key-is-missing-in-dictionary
- Last updated
- 2026-06-07
Public summary
Improve typed dictionary iteration so For Each over Dictionary(Of K, V) exposes key-value pairs whose .Key and .Value members retain the dictionary's key and value types. This would let code such as Dictionary(Of String, String) iteration pass kvp.Value directly to String APIs without requiring .ToString() or manual casts.
Example that should compile after this improvement:
Var entities As Dictionary(Of String, String) = {"amp": "&", "lt": "<"}
Var sTxt As String = "#amp #lt"
For Each kvp As KeyValuePair In entities
sTxt = sTxt.Replace("#" + kvp.Key, kvp.Value)
Next
Today, KeyValuePair.Key and KeyValuePair.Value are exposed as Object, so the second String.Replace argument fails type checking even when the source dictionary is Dictionary(Of String, String).