我正在尝试.Contains()
在自定义对象列表上使用该功能
这是清单:
List<CartProduct> CartProducts = new List<CartProduct>();
和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;
this.Number = Number;
this.CurrentPrice = CurrentPrice;
}
public String ToString()
{
return Name;
}
}
因此,我尝试在列表中找到类似的购物车产品:
if (CartProducts.Contains(p))
但是它忽略了类似的购物车产品,而且我似乎也不知道要检查什么-ID?还是全部?
提前致谢!:)
GetHashCode()
呢?