Uri.ToString Metodo
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene una rappresentazione in forma di stringa canonica per l'istanza di Uri specificata.
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
Rappresentazione canonica senza caratteri escape dell'istanza di Uri. Non viene effettuato l'escape di alcun carattere, ad eccezione di #, ? e %.
Nell'esempio seguente viene creata una nuova Uri istanza da una stringa. Illustra la differenza tra il valore restituito da OriginalString, che restituisce la stringa passata al costruttore e da una chiamata a ToString, che restituisce la forma canonica della stringa.
// Create a new Uri from a string address.
Uri^ uriAddress = gcnew 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 );
// The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
Console::WriteLine( uriAddress->OriginalString );
// 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
La stringa restituita da questo metodo non contiene informazioni sulla porta quando la porta è la porta predefinita per lo schema.
Nota
La stringa restituita dal ToString metodo può contenere caratteri di controllo, che possono danneggiare lo stato di un'applicazione console. È possibile utilizzare il metodo con il GetComponents UriFormat.SafeUnescaped formato per rimuovere i caratteri di controllo dalla stringa restituita.
Prodotto | Versioni |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |