How can I convert a Dictionary<string, string>
to a NameValueCollection
?
The existing functionality of our project returns an old-fashioned NameValueCollection
which I modify with LINQ. The result should be passed on as a NameValueCollection
.
I want to solve this in a generic way. Any hints?
Why not use a simple
foreach
loop?This could be embedded into an extension method:
You could then call it like this:
And if you like LINQ:
Dictionary to NameValueCollection
NameValueCollection to Dictionary
(source)
try this Extension to Dictionary I hope it's what you wanted:
use like
note: I have constrained the key to be string because I didn't want to overgeneralize - of course you can change this with a generic type and .ToString() for the key too.