简体   繁体   English

Linq where element.equals一个数组

[英]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 我想获得关键字等于myKewords中的一个关键字的所有元素

您需要使用Enumerable.Contains方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM