Convert a Dictionary to string of url parameters?

You can use QueryHelpers from Microsoft.AspNetCore.WebUtilities:

string url = QueryHelpers.AddQueryString("https://me.com/xxx.js", dictionary);

One approach would be:

var url = string.Format("http://www.yoursite.com?{0}",
    HttpUtility.UrlEncode(string.Join("&",
        parameters.Select(kvp =>
            string.Format("{0}={1}", kvp.Key, kvp.Value)))));

You could also use string interpolation as introduced in C#6:

var url = $"http://www.yoursite.com?{HttpUtility.UrlEncode(string.Join("&", parameters.Select(kvp => $"{kvp.Key}={kvp.Value}")))}";

And you could get rid of the UrlEncode if you don't need it, I just added it for completeness.


Make a static helper class perhaps:

public static string QueryString(IDictionary<string, object> dict)
{
    var list = new List<string>();
    foreach(var item in dict)
    {
        list.Add(item.Key + "=" + item.Value);
    }
    return string.Join("&", list);
}