在.NET GetHashCode方法中,很多地方都使用.NET 方法.特别是在快速查找集合中的项目或确定相等性时.是否有关于如何GetHashCode为我的自定义类实现覆盖的标准算法/最佳实践,因此我不会降低性能?
我正在尝试.Contains()在自定义对象列表上使用该函数
这是清单:
List<CartProduct> CartProducts = new List<CartProduct>();
Run Code Online (Sandbox Code Playgroud)
而且CartProduct:
public class CartProduct
{
public Int32 ID;
public String Name;
public Int32 Number;
public Decimal CurrentPrice;
/// <summary>
///
/// </summary>
/// <param name="ID">The ID of the product</param>
/// <param name="Name">The name of the product</param>
/// <param name="Number">The total number of that product</param>
/// <param name="CurrentPrice">The currentprice for the product (1 piece)</param>
public CartProduct(Int32 ID, String Name, Int32 Number, Decimal CurrentPrice)
{
this.ID = ID;
this.Name = Name; …Run Code Online (Sandbox Code Playgroud) c# ×2
list ×2
.net ×1
algorithm ×1
class ×1
contains ×1
duplicates ×1
generics ×1
gethashcode ×1
hashcode ×1