c# - Filter items based on an IEnumerable -
I have a list of objects that have a property (product name) that is a I have tried the following, but it seems that all the items that match anything in the IEnumberable filter matches one match (one or a style match): UPDATE have tried to use the answers but I think that should give me an empty set is just one item in FilterProductNames but it still did not give me anything, so I tested the same filter by doing the following: < / P> UPDATE 2 but are not only limited to the items in FilterProductNames therefore extend For example, if I search for items that have Test and Test There are product names of 1, then any item should be brought back which includes both names along with that name Is it possible? You or - probably more efficient - Then you have to return the statement: or IEnumberable & lt; String & gt; . How can I filter this list on the property, so that I only get a list where the item is another
IEnumerable & lt; String & gt; (FilterProductNames) matches all the items?
Items Where (x => x.ProductNames.Intersect (FilterProductNames) Anyone ())
if (count == 1) {// it will return me item 4 item = item Where (x => x.ProductNames.Contains (FilterProductNames.First ())); } Else {// When I remove the above, it will only filter items on the same item item item = item. Where (x => x.ProductNames.All (pn = & gt; filterprintnet.source (pn))); // has tried another version of Tim's reply but no profit: // item = item Where (x => X.ProductNames.Except (FilterProductNames) .no ()); Sorry for the bad words that caused some confusion, I am after those items that put all names in the filter product names.
Enumerable.All :
Items Where (x = & gt; x.ProductNames.All (pn = & gt; Filtrprentnnamksnsadn (pn)))
items. Where (x => X.ProductNames.Except (FilterProductNames) .no ()); Your comment / edit: "... all items containing filter names include all names" Em>
items. Where (x = & amp; ;; Filter ProductName All (FP = & gt; x.ProductNames.Contains (fp)));
items. Where (x = & gt;! Filter ProductName; Leave (x.ProductNames) .no ());
Comments
Post a Comment