1 public static int GetStringHashCode(string value) 2 { 3 int h = 0; // 默认值是0 4 if (value.Length > 0) 5 { 6 for (int i = 0; i < value.Length; i++) 7 { 8 h = 31 * h + value[i]; // val[0]*31^(n-1) + val[1]*31^(n-2) + ... + val[n-1] 9 } 10 } 11 return h; 12 }
标签:string,val,c#,31,value,int,gethashcode From: https://www.cnblogs.com/wzf-Learning/p/16734837.html