C#中如何获取字符串的HashCode?
要获取字符串的HashCode,代码如下,代码如下:
示例
using System;
public class Demo {
public static void Main(String[] args) {
string str1 = "Akon";
string str2 = "Eminem";
Console.WriteLine("String 1 = "+str1);
Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
Console.WriteLine("String 2 = "+str2);
Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2));
}
}输出结果
这将产生以下输出-
String 1 = Akon HashCode of String 1 = 416613838 String 2 = Eminem HashCode of String 2 = 40371907 String 1 is equal to String 2: False
示例
让我们看另一个例子-
using System;
public class Demo {
public static void Main(String[] args) {
string str1 = "Imagine Dragons";
string str2 = "Imagine Dragons";
Console.WriteLine("String 1 = "+str1);
Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
Console.WriteLine("String 2 = "+str2);
Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2));
}
}输出结果
这将产生以下输出-
String 1 = Imagine Dragons HashCode of String 1 = -1546868095 String 2 = Imagine Dragons HashCode of String 2 = -1546868095 String 1 is equal to String 2: True
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬