此方法用於返回此實例的哈希碼。
用法:
public override int GetHashCode ();
返回值:此方法返回32位有符號整數哈希碼。
以下程序說明了Char.GetHashCode()方法的使用:
示例1:
// C# program to demonstrate
// Char.GetHashCode() Method
using System;
class GFG {
// Main Method
public static void Main()
{
// declaring and initializing char
char ch1 = 'B';
// checking condition
// using Equals() Method
int val = ch1.GetHashCode();
// Display Hashcode
Console.WriteLine("Hashcode :- {0}", val);
}
}
輸出:
Hashcode :- 4325442
示例2:
// C# program to demonstrate
// Char.GetHashCode() Method
using System;
class GFG {
// Main Method
public static void Main()
{
// calling hash() Method
hash('a');
hash('b');
hash('c');
hash('x');
hash('y');
hash('z');
}
// Defining hash() Method
public static void hash(char ch)
{
// checking condition
// using Equals() Method
int val = ch.GetHashCode();
// Display Hashcode
Console.WriteLine("Hashcode of " + ch +
" :- {0}", val);
}
}
輸出:
Hashcode of a :- 6357089 Hashcode of b :- 6422626 Hashcode of c :- 6488163 Hashcode of x :- 7864440 Hashcode of y :- 7929977 Hashcode of z :- 7995514
參考:
相關用法
- 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# MathF.Atan()用法及代碼示例
- C# BitArray.RightShift()用法及代碼示例
- C# BitArray.LeftShift()用法及代碼示例
- C# Int16.GetTypeCode用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | Char.GetHashCode() Method with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。