如何创建简单的短哈希值?C#

Smi*_*mit 12 c# hash

如何创建简单的哈希值?例如,我有字符串"TechnologyIsCool"以及如何从此字符串中获取哈希值?

我想做一些方法,如:

public string HashThis(string value)
{
    string hashResult = string.Empty;

    ...

    return hashResult;
}
Run Code Online (Sandbox Code Playgroud)

并将此方法称为:

string hash = HashThis("TechnologyIsCool");
Run Code Online (Sandbox Code Playgroud)

之后就像"5qazws"那样哈希.

Hab*_*bib 13

使用String.GetHashCode方法

 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 );
}
Run Code Online (Sandbox Code Playgroud)

  • 哈希码可以在不同的运行时间上变化.可以在此处找到适用于此解决方案的一些警告:http://stackoverflow.com/questions/1116860/whats-the-best-way-to-create-a-short-hash-similiar-to-what-tiny-网址不 (5认同)

dts*_*tsg 6

使用 GetHashCode();

public string HashThis(string value)
{
    return hashResult = value.GetHashCode();
}
Run Code Online (Sandbox Code Playgroud)

  • 哈希码可以在不同的运行时间上变化.可以在此处找到适用于此解决方案的一些警告:http://stackoverflow.com/questions/1116860/whats-the-best-way-to-create-a-short-hash-similiar-to-what-tiny-网址不 (6认同)