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
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语