您不能通过在它们之间放置 AND 来简单地查询两个不同的数组。试试下面的代码:
var moreScores = new int[] { 12, 12, 45, 45, 87, 96 };
var scores = new int[] { 97, 92, 81, 60 };
var scoreQueryResults =
from score in (scores.Union(moreScores))
where score > 80
select score;
还有一些 Linq 的通用示例。
var list = new List<string>();
// ... add some items
// Searching for the strings that starts with J AND ends K
// Method Chain Format
var results1 = list.Where(item => item.StartsWith("J") && item.EndsWith("K"));
// Query Format
var results2 = from item in list
where item.StartsWith("J") && item.EndsWith("K")
select item;
// Searching for the strings that starts with J OR K
// Method Chain Format
var results3 = list.Where(item => item.StartsWith("J") || item.StartsWith("K"));
// Query Format
var results4 = from item in list
where item.StartsWith("J") || item.StartsWith("K")
select item;