string urlString = "https://example.com/path/to/resource?param1=value1¶m2=value2"; Uri uri = new Uri(urlString); Console.WriteLine(uri.Scheme); // Outputs "https" Console.WriteLine(uri.Host); // Outputs "example.com" Console.WriteLine(uri.PathAndQuery); // Outputs "/path/to/resource?param1=value1¶m2=value2"
var builder = new UriBuilder { Scheme = "https", Host = "example.com", Path = "path/to/resource", }; builder.Query = "param1=value1¶m2=value2"; var uri = builder.Uri; Console.WriteLine(uri.ToString()); // Outputs "https://example.com/path/to/resource?param1=value1¶m2=value2"The Url class is part of the System assembly which is part of the .NET Framework.