用于搜索列表的过滤器<object>
Filters for searching a list<object>
假设我有一个具有以下定义的对象:
class Obj {
public string Id;
public string Vendor;
public string Type;
}
然后是列表:
List<Obj>
我有一个 checkedlistbox 组件,用户可以在其中 select 筛选到 return 结果。
示例:
用户检查[cb1 = VENDORX, cb2 = VENDORY, cb3 = TYPEONE]
return 一个列表,其中 Obj.Vendor = VENDORX or VENDORY and Obj.Type = TYPEONE
使用 LinQ
var filtered = objs.Where(o => o.Vendor is "VENDOROX" or "VENDORY" && o.Type == "TYPEONE");
// same as
var filtered = objs.Where(o => (o.Vendor == "VENDOROX" || o.Vendor == "VENDORY") && o.Type == "TYPEONE");
假设我有一个具有以下定义的对象:
class Obj {
public string Id;
public string Vendor;
public string Type;
}
然后是列表:
List<Obj>
我有一个 checkedlistbox 组件,用户可以在其中 select 筛选到 return 结果。
示例:
用户检查[cb1 = VENDORX, cb2 = VENDORY, cb3 = TYPEONE]
return 一个列表,其中 Obj.Vendor = VENDORX or VENDORY and Obj.Type = TYPEONE
使用 LinQ
var filtered = objs.Where(o => o.Vendor is "VENDOROX" or "VENDORY" && o.Type == "TYPEONE");
// same as
var filtered = objs.Where(o => (o.Vendor == "VENDOROX" || o.Vendor == "VENDORY") && o.Type == "TYPEONE");