(自学日记)C#BindingList多条件模糊查询查找

List或BindingList查找精确的用Find或者FirstOrDefault。

ClassProduct是个类

 public class ClassProduct
 {
     /// <summary>
     /// 品号
     /// </summary>
     public string ID
     {
         get;
         set;
     }
     /// <summary>
     /// 品名
     /// </summary>
     public string Name
     {
         get;
         set;
     }
     /// <summary>
     /// 规格
     /// </summary>
     public string Type
     {
         get;
         set;
     }
     /// <summary>
     /// 单位
     /// </summary>
     public string Unit
     {
         get;
         set;
     }
     /// <summary>
     /// 数量
     /// </summary>
     public float Quantity
     {
         get;
         set;
     }
 }

单条件的模糊查询

List<ClassProduct> showQuery = new List<ClassProduct>();
string str1 = textID.Text;
string str2 = textName.Text;
string str3 = textType.Text;
string str4 = textUnit.Text;

showQuery = Global.listProductDictionary.Where(fuzzy => fuzzy.Name.Contains(str1)).ToList();

多条件的模糊查询

showQuery = (from product in Global.listProductDictionary where
             product.ID.ToString().Contains(str1) && product.Name.Contains(str2) && product.Type.Contains(str3) && product.Type.Contains(str4)
             select product).ToList();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值