var url = new UriBuilder("https://www.example.com"); var query = HttpUtility.ParseQueryString(url.Query); query.Add("name", "John"); url.Query = query.ToString(); Console.WriteLine(url.ToString());
var url = new UriBuilder("https://www.example.com"); var query = HttpUtility.ParseQueryString(url.Query); query.Add("name", "John"); query.Add("age", "30"); query.Add("location", "New York"); url.Query = query.ToString(); Console.WriteLine(url.ToString());In this example, we add three key-value pairs to the query string: "name=John", "age=30", and "location=New York". The AddKey method is part of the System.Web namespace in C#, which is included in the .NET Framework.