How to create simple short hash value? C#
17,046
Solution 1
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 );
}
Solution 2
Use GetHashCode();
public string HashThis(string value)
{
return hashResult = value.GetHashCode();
}
Solution 3
No you cannot use String.GetHashCode() because this does not guarantee to return the same hash on the same string every time.
Comments
-
Smit about 2 years
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".