通过指定多个条件在通用列表中查找项目 [英] Find an item in a generic list by specifying multiple conditions

查看:138
本文介绍了通过指定多个条件在通用列表中查找项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数情况下,我们会找到带有以下代码的通用列表:

Most often we find generic list with code like:

CartItem Item = Items.Find(c => c.ProductID == ProductID);
Item.Quantity = Quantity;
Item.Price = Price;

因此,上面的代码查找并更新了其他数据,但是如果我想在多个条件下查找,那我该如何编写代码?

So the above code finds and updates with other data, but if I want to find by multiple conditions, then how do I write the code?

我想编写如下代码:

CartItem Item = Items.Find(c => c.ProductID == ProductID and c.ProductName == "ABS001");

找到通用列表时,请为我提供多种条件的指导.

Please guide me for multiple conditions when we find generic list.

推荐答案

尝试一下:

CartItem Item = Items.Find(c => (c.ProductID == ProductID) && (c.ProductName == "ABS001"));

这篇关于通过指定多个条件在通用列表中查找项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆