ServicePoint のハッシュ コードを取得します。
Overrides Public Function GetHashCode() As Integer
[C#]
public override int GetHashCode();
[C++]
public: int GetHashCode();
[JScript]
public override function GetHashCode() : int;
戻り値
ServicePoint のハッシュ コード。
解説
A.Equals(B)
が true の場合、 ServicePoint A
および B
のハッシュ コードは同じです。
このメソッドは、 Object.GetHashCode メソッドを実装します。
使用例
[Visual Basic, C#, C++] GetHashCode メソッドを使用して、2 つの HttpWebRequest インスタンスが同じ ServicePoint を示しているかどうかを判断する例を次に示します。
' Create the first 'HttpWebRequest' object.
Dim myWebRequest1 As HttpWebRequest = CType(WebRequest.Create("https://www.microsoft.com"), HttpWebRequest)
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myWebResponse1 As HttpWebResponse = CType(myWebRequest1.GetResponse(), HttpWebResponse)
Dim myServicePoint1 As ServicePoint = myWebRequest1.ServicePoint
' Create the second 'HttpWebRequest' object with the same hostfragment as above.
Dim myWebRequest2 As HttpWebRequest = CType(WebRequest.Create("https://www.microsoft.com/windows"), HttpWebRequest)
Dim myWebResponse2 As HttpWebResponse = CType(myWebRequest2.GetResponse(), HttpWebResponse)
Dim myServicePoint2 As ServicePoint = myWebRequest2.ServicePoint
Console.WriteLine("The 'HashCode' for the first connection is:" + myServicePoint1.GetHashCode().ToString())
Console.WriteLine("The 'HashCode' for the second connection is:" + myServicePoint2.GetHashCode().ToString())
' Check whether the first and second 'HttpWebRequest' objects connecting to the same internet
' server are using the same 'ServicePoint' or not
If myServicePoint1.GetHashCode().Equals(myServicePoint2.GetHashCode()) Then
Console.WriteLine(ControlChars.Cr + "Two connections are created to the same Internet Server")
Console.WriteLine("So same 'ServicePoint' is used for both the Connections")
End If
[C#]
// Create the first 'HttpWebRequest' object.
HttpWebRequest myWebRequest1 = (HttpWebRequest) WebRequest.Create("https://www.microsoft.com");
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse myWebResponse1 =(HttpWebResponse)myWebRequest1.GetResponse();
ServicePoint myServicePoint1 = myWebRequest1.ServicePoint;
// Create the second 'HttpWebRequest' object with the same hostfragment as above.
HttpWebRequest myWebRequest2 =(HttpWebRequest) WebRequest.Create("https://www.microsoft.com/windows");
HttpWebResponse myWebResponse2 =(HttpWebResponse)myWebRequest2.GetResponse();
ServicePoint myServicePoint2 = myWebRequest2.ServicePoint;
Console.WriteLine("\nThe 'HashCode' for the first connection is:"+myServicePoint1.GetHashCode());
Console.WriteLine("The 'HashCode' for the second connection is:"+myServicePoint2.GetHashCode());
// Check whether the first and second 'HttpWebRequest' objects connecting to the same internet
// server are using the same 'ServicePoint' or not
if(myServicePoint1.GetHashCode().Equals(myServicePoint2.GetHashCode()))
{
Console.WriteLine("\nTwo connections are created to the same Internet Server");
Console.WriteLine("So same 'ServicePoint' is used for both the Connections");
}
// Release all the response object resources.
myWebResponse1.Close();
myWebResponse2.Close();
[C++]
// Create the first 'HttpWebRequest' object.
HttpWebRequest* myWebRequest1 =
dynamic_cast<HttpWebRequest*> (WebRequest::Create(S"https://www.microsoft.com"));
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse* myWebResponse1 =
dynamic_cast<HttpWebResponse*>(myWebRequest1->GetResponse());
ServicePoint* myServicePoint1 = myWebRequest1->ServicePoint;
// Create the second 'HttpWebRequest' object with the same hostfragment as above.
HttpWebRequest* myWebRequest2 =
dynamic_cast<HttpWebRequest*> (WebRequest::Create(S"https://www.microsoft.com/windows"));
HttpWebResponse* myWebResponse2 =
dynamic_cast<HttpWebResponse*>(myWebRequest2->GetResponse());
ServicePoint* myServicePoint2 = myWebRequest2->ServicePoint;
Console::WriteLine(S"\nThe 'HashCode' for the first connection is: {0}",
__box(myServicePoint1->GetHashCode()));
Console::WriteLine(S"The 'HashCode' for the second connection is: {0}",
__box(myServicePoint2->GetHashCode()));
// Check whether the first and second 'HttpWebRequest' objects connecting to the same internet
// server are using the same 'ServicePoint' or not
if ( __box(myServicePoint1->GetHashCode()) -> Equals(__box(myServicePoint2->GetHashCode()) ) ) {
Console::WriteLine(S"\nTwo connections are created to the same Internet Server");
Console::WriteLine(S"So same 'ServicePoint' is used for both the Connections");
}
// Release all the response object resources.
myWebResponse1->Close();
myWebResponse2->Close();
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard