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();