c# - Filter a collection with like operator from a string collection -


i have string collection:

["1-","2-","4-"] 

i have collection of classes.

class:

public class productionparameter     {         public string companycode { get; set; }         public string unitcode { get; set; }         public string itemdescriptionlocal { get; set; }         public string itemdescriptionenglish { get; set; }         public string consumeditemdescriptionlocal { get; set; }         public string consumeditemdescriptionenglish { get; set; }         public string lotcategory1description { get; set; }         public string lotcategory2description { get; set; }         public string lotcategory3description { get; set; }         public string lotcategory1code { get; set; }         public string lotcategory2code { get; set; }         public string lotcategory3code { get; set; }         public string linecode { get; set; }         public string linecodedisplay { get; set; }         public string itemuom1 { get; set; }         public string itemuom2 { get; set; }         public string consumeditemuom1 { get; set; }         public string consumeditemuom2 { get; set; }         public string workshift { get; set; }     } 

i want members of collection linecode property within string collection operation.

example: want check every class in list of productionparmaters , keep instances linecode property :

(like '1-%' or '2-%' or '4-%') 

you use linq that: assuming stringcollection the string collection post , lstproductionparameter objects list collection refer.

after edit of question, i'll give 2 possible answers:

1) if need check if value or linecode has of values in string, can go way:

var lstproductionparameterfiltered = lstproductionparameter.where(c => stringcollection.any(s => c.linecode.contains(s))); 

in case area using stringcollection class (i'd prefer use list or array btw) cast stringcollection this:

var lstproductionparameterfiltered = lstproductionparameter.where(c => ((ienumerable<string>)stringcollection).any(s => c.linecode.contains(s))); 

2) if need check if of stringcollection has linecode, can go way:

var lstproductionparameterfiltered = lstproductionparameter.where(c => stringcollection.contains(c.linecode)); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -