我正在尝试.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) 如果我有一个类型的对象MyBull和一个List<MyBull> orig:
// Just an example
MyBull x = getMeTheObjectWithIdFromDB(9);
orig.add(x);
// Again same? data object
MyBull y = getMeTheObjectWithIdFromDB(9);
Run Code Online (Sandbox Code Playgroud)
为什么这是假的呢?
// This is false, even though all the properties
// of x and y are the same.
orig.Contains<MyBull>(y);
Run Code Online (Sandbox Code Playgroud)