using System; public class Entity { public int EntityID { get; set; } public string EntityName { get; set; } public override int GetHashCode() { unchecked { int hash = 15485863; int multiplier = 1299709; hash = hash * multiplier + EntityID.GetHashCode(); hash = hash * multiplier + (EntityName != null ? EntityName.GetHashCode() : 0); return hash; } } } public class Test { public static void Main() { var hash1 = new Entity { EntityID = 1337, EntityName = "" }.GetHashCode(); var hash2 = new Entity { EntityID = 1337, EntityName = null }.GetHashCode(); Console.WriteLine(hash1 == hash2); } }