Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq where element.equals one array

Tags:

c#

.net

linq

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

like image 805
daniel Avatar asked Mar 05 '26 06:03

daniel


1 Answers

You need to use the Enumerable.Contains method:

var temp = (from e in table where myKeywords.Contains(e.Keyword)).ToArray();
like image 106
Jon Avatar answered Mar 06 '26 19:03

Jon