Skip to content

Instantly share code, notes, and snippets.

@joseftw
Last active April 19, 2018 08:30
Show Gist options
  • Save joseftw/a81e283820ea6fce14ff762320b7f9ba to your computer and use it in GitHub Desktop.
Save joseftw/a81e283820ea6fce14ff762320b7f9ba to your computer and use it in GitHub Desktop.
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