C# 中的 SByte.GetHashCode() 方法與示例
C# 中的 SByte.GetHashCode() 方法用於返回此例項的雜湊程式碼。
語法
語法如下 −
public override int GetHashCode ();
示例
現在我們來看一個示例 −
using System;
public class Demo {
public static void Main() {
sbyte s1 = 50;
sbyte s2 = 75;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
Console.WriteLine("Is s1 and s2 equal? = "+s1.Equals(s2));
Console.WriteLine("HashCode for s1 = "+s1.GetHashCode());
Console.WriteLine("HashCode for s2 = "+s1.GetHashCode());
}
}輸出
這將生成以下輸出 −
Value of S1 = 50 Value of S2 = 75 Is s1 and s2 equal? = False HashCode for s1 = 50 HashCode for s2 = 50
示例
現在,讓我們來看另一個示例 −
using System;
public class Demo {
public static void Main() {
sbyte s1 = 55;
object s2 = (sbyte)55;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
int res = s1.CompareTo(s2);
if (res > 0)
Console.WriteLine("s1 > s2");
else if (res < 0)
Console.WriteLine("s1 < s2");
else
Console.WriteLine("s1 = s2");
Console.WriteLine("HashCode for s1 = "+s1.GetHashCode());
Console.WriteLine("HashCode for s2 = "+s1.GetHashCode());
}
}輸出
這將生成以下輸出 −
Value of S1 = 10 Value of S2 = 100 s1 < s2 HashCode for s1 = 2570 GetTypeCode for s1 = SByte HashCode for s2 = 25700 GetTypeCode for s2 = SByte
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP