Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

Filter a genric list T, with a string value

I Have a list T, would like to know if I could filter this list based on a stirng which has the filter criteria.

filter string =  "Type = 'Shoes' AND Code = 'ABC' AND ProductGroup = 'InStock "

list T, T has properties
Type
Code
ProductGroup
Avatar of p_davis
p_davis

you can use lambda expression

List<yourType> filteredList = yourList.FindAll(x=> x.Type == "Shoes" && x.Code == "ABC" && x.ProductGroup == "InStock");
*No points*

I'd just add for informational purposes that p_davis' suggestion won't create new objects; it will just create a set of new references to the existing objects. This may or may not be a concern for your needs.
ASKER CERTIFIED SOLUTION
Avatar of countrymeister
countrymeister

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
May I inquire:  How are you building that filter string?
Avatar of countrymeister

ASKER

kaufmed,

I have a pivot grid, and when the user selects a cell in the grid, I find the header of the column and the row header and build my string. in the cell click event.
I found my own solution