How to create simple hash value? For example I have string "TechnologyIsCool" and how to have hash value from this string?
I want to do some method like:
public string HashThis(string value)
{
string hashResult = string.Empty;
...
return hashResult;
}
and call this method like:
string hash = HashThis("TechnologyIsCool");
and after that have hash like "5qazws".
public static void Main()
{
DisplayHashCode( "Abcdei" );
}
static void DisplayHashCode( String Operand )
{
int HashCode = Operand.GetHashCode( );
Console.WriteLine("The hash code for \"{0}\" is: 0x{1:X8}, {1}",
Operand, HashCode );
}
Use GetHashCode();
public string HashThis(string value)
{
return hashResult = value.GetHashCode();
}
不,你不能使用String.GetHashCode(),因为这不保证每次都在同一个字符串上返回相同的哈希。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.