Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create simple short hash value? C#

Tags:

c#

hash

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".

like image 258
Smit Avatar asked May 16 '12 10:05

Smit


1 Answers

Use String.GetHashCode Method

 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 );
}
like image 183
Habib Avatar answered Sep 21 '22 06:09

Habib