首页 新闻 会员 周边 捐助

真不好意思问个基础问题,HashSet<T> 的 Contains()不出正确结果

0
悬赏园豆:20 解决于 2013-09-13 15:37
 HashSet<OrderDetailItem> list = new HashSet<OrderDetailItem>();

 list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938838", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938837", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338898", Barcode = "51023079339938836", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938835", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338898", Barcode = "51023079339938834", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938833", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938832", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938831", Num = 1 });
            list.Add(new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938830", Num = 1 });

 var item = new OrderDetailItem() { OrderNo = "23232322323", ProductCode = "338899", Barcode = "51023079339938837", Num = 1 };
            var mbEntity = list.Where(d => d.Barcode == item.Barcode).FirstOrDefault();
            bool b = list.Contains(item);

//为什么b老是false
c#
数据酷软件的主页 数据酷软件 | 初学一级 | 园豆:130
提问于:2013-09-13 14:01
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册