Uri.ToString Metódus

Definíció

Lekéri a megadott Uri példányhoz tartozó canonical string-reprezentációt.

public:
 override System::String ^ ToString();
public override string ToString();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Válaszok

A példány nem használható canonical reprezentációja Uri . A #, a ?, és a %kivételével az összes karakter le van bontva.

Példák

Az alábbi példa egy új Uri példányt hoz létre egy sztringből. A függvény a konstruktornak átadott sztringet OriginalStringvisszaadó érték és a meghívás ToStringközötti különbséget mutatja be, amely a sztring canonikus formáját adja vissza.

// Create a new Uri from a string address.
Uri uriAddress = new Uri("HTTP://www.Contoso.com:80/thick%20and%20thin.htm");

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version.  OriginalString gives the orginal
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com/thick and thin.htm".
Console.WriteLine(uriAddress.ToString());

// The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
Console.WriteLine(uriAddress.OriginalString);
// Create a new Uri from a string address.
let uriAddress = Uri "HTTP://www.Contoso.com:80/thick%20and%20thin.htm"

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version.  OriginalString gives the orginal
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com/thick and thin.htm".
printfn $"{uriAddress.ToString()}"

// The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
printfn $"{uriAddress.OriginalString}"
    ' Create a new Uri from a string address.
    Dim uriAddress As New Uri("HTTP://www.Contoso.com:80/thick%20and%20thin.htm")
    
    ' Write the new Uri to the console and note the difference in the two values.
    ' ToString() gives the canonical version.  OriginalString gives the orginal 
    ' string that was passed to the constructor.
    ' The following outputs "http://www.contoso.com/thick and thin.htm".
    Console.WriteLine(uriAddress.ToString())
    
    ' The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
    Console.WriteLine(uriAddress.OriginalString)

End Sub

Megjegyzések

A metódus által visszaadott sztring nem tartalmaz portinformációt, ha a séma alapértelmezett portja a port.

Note

A metódus által visszaadott sztring ToString vezérlőkarakterekből állhat, amelyek ronthatják a konzolalkalmazás állapotát. A metódus formátumával eltávolíthatja a GetComponentsUriFormat.SafeUnescaped vezérlőkaraktereket a visszaadott sztringből.

A következőre érvényes: