Single.GetHashCode()方法用于返回此实例的哈希码。
用法: public override int GetHashCode ();
返回值:此方法返回32位有符号整数哈希码。
以下示例程序旨在说明Single.GetHashCode()方法的使用:
示例1:
// C# program to demonstrate the
// Single.GetHashCode() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
float value1 = 10f;
// getting the HashCode
// using GetHashCode() method
int value = value1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode is {0}", value);
}
}
输出:
HashCode is 1092616192
示例2:
// C# program to demonstrate the
// Single.GetHashCode() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
get(5f);
get(9.5f);
get(10000f);
get(2327.5232f);
}
// defining get() method
public static void get(float value1)
{
// getting the HashCode
// using GetHashCode() method
int value = value1.GetHashCode();
// Display the HashCode
Console.WriteLine("HashCode is {0}", value);
}
}
输出:
HashCode is 1084227584 HashCode is 1092091904 HashCode is 1176256512 HashCode is 1158772831
参考:
相关用法
- C# MathF.Tan()用法及代码示例
- C# MathF.Abs()用法及代码示例
- C# MathF.Max()用法及代码示例
- C# MathF.Log()用法及代码示例
- C# MathF.Min()用法及代码示例
- C# MathF.Cos()用法及代码示例
- C# MathF.Exp()用法及代码示例
- C# MathF.Pow()用法及代码示例
- C# MathF.Sin()用法及代码示例
- C# UInt16.GetHashCode用法及代码示例
- C# Single.IsNegative()用法及代码示例
- C# Single.IsFinite()用法及代码示例
- C# Single.CompareTo()用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Single.GetHashCode() Method in C# with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。