Uri.GetHashCode 方法

定义

获取 URI 的哈希代码。

public:
 override int GetHashCode();
public override int GetHashCode ();
override this.GetHashCode : unit -> int
Public Overrides Function GetHashCode () As Integer

返回

Int32

为此 URI 生成的哈希值。

示例

以下示例创建一个 Uri 实例,并将哈希代码写入控制台。

// Create Uri
Uri^ uriAddress = gcnew Uri( "http://www.contoso.com/index.htm#search" );
Console::WriteLine( uriAddress->Fragment );
Console::WriteLine( "Uri {0} the default port ", uriAddress->IsDefaultPort ? (String^)"uses" : "does not use" );

Console::WriteLine( "The path of this Uri is {0}", uriAddress->GetLeftPart( UriPartial::Path ) );
Console::WriteLine( "Hash code {0}", uriAddress->GetHashCode() );
// The example displays output similar to the following:
//        #search
//        Uri uses the default port
//        The path of this Uri is http://www.contoso.com/index.htm
//        Hash code -988419291
// Create Uri
Uri uriAddress = new Uri("http://www.contoso.com/index.htm#search");
Console.WriteLine(uriAddress.Fragment);
Console.WriteLine("Uri {0} the default port ", uriAddress.IsDefaultPort ? "uses" : "does not use");

Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path));
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode());
// The example displays output similar to the following:
//        #search
//        Uri uses the default port
//        The path of this Uri is http://www.contoso.com/index.htm
//        Hash code -988419291
// Create Uri
let uriAddress = Uri "http://www.contoso.com/index.htm#search"
printfn $"{uriAddress.Fragment}"
printfn $"""Uri {if uriAddress.IsDefaultPort then "uses" else "does not use"} the default port """

printfn $"The path of this Uri is {uriAddress.GetLeftPart UriPartial.Path}"
printfn $"Hash code {uriAddress.GetHashCode()}"
// The example displays output similar to the following:
//        #search
//        Uri uses the default port
//        The path of this Uri is http://www.contoso.com/index.htm
//        Hash code -988419291
' Create Uri
Dim uriAddress As New Uri("http://www.contoso.com/index.htm#search")
Console.WriteLine(uriAddress.Fragment)
Console.WriteLine("Uri {0} the default port ", If(uriAddress.IsDefaultPort, "uses", "does not use")) 

Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path))
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode())
' The example displays output similar to the following:
'        #search
'        Uri uses the default port
'        The path of this Uri is http://www.contoso.com/index.htm
'        Hash code -988419291

适用于