fork download
  1. using System;
  2.  
  3. public class Entity {
  4. public int EntityID { get; set; }
  5. public string EntityName { get; set; }
  6.  
  7. public override int GetHashCode() {
  8. unchecked {
  9. int hash = 15485863;
  10. int multiplier = 1299709;
  11.  
  12. hash = hash * multiplier + EntityID.GetHashCode();
  13. hash = hash * multiplier + (EntityName != null ? EntityName.GetHashCode() : 0);
  14.  
  15. return hash;
  16. }
  17. }
  18. }
  19.  
  20. public class Test
  21. {
  22. public static void Main()
  23. {
  24. var hash1 = new Entity { EntityID = 1337, EntityName = "" }.GetHashCode();
  25. var hash2 = new Entity { EntityID = 1337, EntityName = null }.GetHashCode();
  26.  
  27. Console.WriteLine(hash1 == hash2);
  28. }
  29. }
Success #stdin #stdout 0.02s 24160KB
stdin
Standard input is empty
stdout
True