Skip to content

1.0.0

Choose a tag to compare

@gilad-teller gilad-teller released this 26 Mar 20:04
· 4 commits to main since this release

QueryStringHelper

C# Helper library for building Query string

Use the static method to create a query string from a dictionary:

Dictionary<string, int> parameters = new()
{
    ["a"] = 1,
    ["b"] = 2
};
string queryString = QueryStringHelper.BuildQueryString(parameters);
Console.WriteLine(queryString); //a=1&b=2

Use the UriBuilder extension method to add the query string to the a URI:

Dictionary<string, string> parameters = new()
{
    ["a"] = "1",
    ["b"] = "2"
};
UriBuilder builder = new UriBuilder("http://www.sample.com")
    .AddQueryString(parameters);
string uri = builder.Uri.ToString();
Console.WriteLine(uri); //http://www.sample.com/?a=1&b=2