Boolean.GetHashCode()方法用於返回此實例的哈希碼。
用法: public override int GetHashCode ();
返回值:此方法返回32位有符號整數哈希碼。
以下示例程序旨在說明Boolean.GetHashCode()方法的使用:
示例1:
// C# program to demonstrate the
// Boolean.GetHashCode() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
bool value1 = true;
// getting the HashCode
// using GetHashCode() method
int value = value1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode is {0}", value);
}
}
輸出:
HashCode is 1
示例2:
// C# program to demonstrate the
// Boolean.GetHashCode() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get(true);
get(false);
}
// defining get() method
public static void get(bool value1)
{
// getting the HashCode
// using GetHashCode() method
int value = value1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode is {0}", value);
}
}
輸出:
HashCode is 1 HashCode is 0
參考:
相關用法
- C# MathF.Exp()用法及代碼示例
- C# MathF.Cos()用法及代碼示例
- C# MathF.Tan()用法及代碼示例
- C# MathF.Abs()用法及代碼示例
- C# MathF.Min()用法及代碼示例
- C# MathF.Sin()用法及代碼示例
- C# MathF.Pow()用法及代碼示例
- C# MathF.Log()用法及代碼示例
- C# MathF.Max()用法及代碼示例
- C# MathF.Cbrt()用法及代碼示例
- C# Char.GetTypeCode()用法及代碼示例
- C# Char.GetHashCode()用法及代碼示例
- C# MathF.Atan()用法及代碼示例
- C# BitArray.RightShift()用法及代碼示例
- C# BitArray.LeftShift()用法及代碼示例
注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 Boolean.GetHashCode() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。