2

我可以简单地通过

   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 中的关键字之一的所有元素

4

2 回答 2

10

您需要使用以下Enumerable.Contains方法:

var temp = (from e in table where myKeywords.Contains(e.Keyword)).ToArray();
于 2012-08-03T12:07:39.593 回答
0
string[] temp = (from e in table
                 join k in myKeywords on  e.Keyword equals k
                 select e.Keyword).ToArray();
于 2012-08-03T12:15:28.763 回答