2012-08-03 50 views
1

我可以简单地通过LINQ的地方element.equals一个阵列

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

得到一个数组的一个项目我怎样才能把它扩展到一个数组中?我想是这样的:

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

我想要得到的所有元素,其中的关键字等于关键字之一myKewords

+0

看看这个:http://stackoverflow.com/questions/8043151/linq-in-operator – 2012-08-03 12:07:28

回答

8

您需要使用Enumerable.Contains方法:

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