Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.SkeetJ.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin support for GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin support for GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin support for GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

added 23 characters in body
Source Link
Tim Schmelter
  • 461.8k
  • 79
  • 719
  • 980

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin support for GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin support for GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

added 217 characters in body
Source Link
Tim Schmelter
  • 461.8k
  • 79
  • 719
  • 980

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Instead of concatenating strings (which creates new strings) you could use XOR or even better simple maths (credits to J.Skeet):

public int keygen(string a, string b, string c) { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + a == null ? 0 : a.GetHashCode(); hash = hash * 23 + b == null ? 0 : b.GetHashCode(); hash = hash * 23 + c == null ? 0 : c.GetHashCode(); return hash; } } 

In general it's not necessary to produce unique hashs. But you should minimize collisions.

Another(not as efficient) way is to use an anonymous type which has a builtin GetHashCode:

public int keygen(string a, string b, string c) { return new { a, b, c }.GetHashCode(); } 

Note that the name, type and order matters for the calculation of the hashcode of an anonymous type.

Source Link
Tim Schmelter
  • 461.8k
  • 79
  • 719
  • 980
Loading