Skip to content

Instantly share code, notes, and snippets.

Last active Apr 19, 2018
What would you like to do?
public static class NameValueCollectionExtensions {
public static string ToQueryString(this NameValueCollection nameValueCollection) {
return string.Join("&", nameValueCollection
.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