daniel
daniel

Reputation: 35693

Linq where element.equals one array

i can simply get one item of an array by

   string myKeyword="test";
   GridView1.DataSource = from e in table where e.Keyword.Equals(myKeyword) select e;

how can i extend it to an array? I want something like:

   string[] myKeywords={"test1", "test"};
   GridView1.DataSource = from e in table where e.Keyword.Equals(myKeywords) select e; // something like this?

i want to get all elements where the Keyword is equal to one of the the Keywords in myKewords

Upvotes: 2

Views: 1828

Answers (2)

Daniel
Daniel

Reputation: 632

string[] temp = (from e in table
                 join k in myKeywords on  e.Keyword equals k
                 select e.Keyword).ToArray();

Upvotes: 0

Jon
Jon

Reputation: 437336

You need to use the Enumerable.Contains method:

var temp = (from e in table where myKeywords.Contains(e.Keyword)).ToArray();

Upvotes: 10

Related Questions