Skip to content

Instantly share code, notes, and snippets.

@joseftw
Last active Apr 19, 2018
Embed
What would you like to do?
public static class NameValueCollectionExtensions {
public static string ToQueryString(this NameValueCollection nameValueCollection) {
return string.Join("&", nameValueCollection
.AllKeys
.SelectMany(key => (nameValueCollection.GetValues(key) ?? Enumerable.Empty<string>())
.Select(val => string.Concat(key, "=", WebUtility.UrlEncode(val)))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment