Uri uri = new Uri("https://www.example.com/search?q=apple"); NameValueCollection query = System.Uri.ParseQueryString(uri.Query); string queryValue = query["q"];
Uri uri = new Uri("https://www.example.com/search?q=apple&lang=en&sort=relevance"); NameValueCollection query = System.Uri.ParseQueryString(uri.Query); string queryValue1 = query["q"]; string queryValue2 = query["lang"]; string queryValue3 = query["sort"];In this example, we have a URI with three parameters in the query string. We call the ParseQueryString method as before and retrieve each parameter value by accessing the corresponding key in the NameValueCollection. The package library for the System.Uri.ParseQueryString method is the .NET Framework class library, which is included with the .NET Framework SDK.