我有一個產品類,如何創建實例的哈希?
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string ModelNumber { get; set; }
public string Sku { get; set; }
public string Description { get; set; }
public double Price { get; set; }
public double NewPrice { get; set; }
}
我保存這個類在我的數據庫表。但我還需要將每個對象的散列保存在我的數據庫表中以進行更改跟蹤。我尋找的是,
var p1 = new Product{
Id =2,
Name = "1",
ModelNumber = "4"
};
var p2 = new Product
{
Id = 2,
Name = "1",
ModelNumber = "4"
};
var hashOfp1 = Hash(p1);
var hashOfp2 = Hash(p2);
// This should return true because both objects have same values
if(hashOfp1 == hashOfp2){
}
見基於對象屬性這個答案讓哈希碼:http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system -object-gethashcode – Smudge202 2014-09-03 08:14:25