我有以下语句:
foreach (var textBlock in scoresGrid.Children.OfType<TextBlock>().Where(three => three.Name.Contains("Three")))
我怎样才能使它变成where name contain three or four
呢?
请帮助。由于
使用或||
运算符组合where子句中的条件。
foreach (var textBlock in scoresGrid.Children.OfType<TextBlock>()
.Where(three => three.Name.Contains("Three") || three.Name.Contains("Four")))
string[] names = { "Three", "Four" } ;
foreach (var textBlock in scoresGrid.Children.OfType<TextBlock>()
.Where(tb => names.Any(name => tb.Name.Contains(name))))
我也认为你的foreach语句有点难读。首先获得过滤的textBlocks。
可以使用逻辑运算符。For or是'||'>().Where(three => three.Name.Contains("Three") || three.Name.Contains("Four")))