System.Uri.Query Property

Gets any query information included in the specified URI.

Syntax

public string Query { get; }

Value

A string containing the query information included in the specified URI, or string.Empty .

Remarks

The Uri.Query property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information returned includes the leading question mark.

The query information is escaped according to RFC 2396 by default. If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing is enabled, the query information is escaped according to RFC 3986 and RFC 3987.

For more information on IRI support, see the Remarks section for the Uri class.

Example

The following example uses the Uri.Query property to extract the query from a URI.

C# Example

using System;

public class UriTest {
 public static void Main() {

 Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.Query);
 }
}

The output is

?date=today

Requirements

Namespace: System
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0