Home > Mobile >  Filters for searching a list<object>
Filters for searching a list<object>

Time:06-02

Let's say I have an Object with the following definition:

class Obj {
    public string Id;
    public string Vendor;
    public string Type;
}

then a list:

List<Obj>

I have a checkedlistbox component where the user can select the filters to return results.

Example:

User check [cb1 = VENDORX, cb2 = VENDORY, cb3 = TYPEONE]

return a list where Obj.Vendor = VENDORX or VENDORY and Obj.Type = TYPEONE

CodePudding user response:

Using 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");
  •  Tags:  
  • c#
  • Related