LINQ查询中的Where子句使用函数

Sai*_*and 1 c# linq

我有一段代码:

IList<Opportunity> filteredOpportunityProperties = new List<Opportunity>();
List<LookupWithIntId> selectedProperties = opportunityFilter.PropertyTypes;
List<string> propertyTypes = selectedProperties.Select(item => item.Name).ToList();

opportunities.Where((item) =>
    {
        string productType = item.Properties[0].ProductType;
        bool propertyMatch = propertyTypes.Any(propTypes => productType.Contains(propTypes));
        if (propertyMatch) select item;
    });
Run Code Online (Sandbox Code Playgroud)

如果条件匹配,我想要选择该项.但是,我收到错误:

嵌入式语句不能是声明或带标签的语句

有什么建议!

Ahm*_*eed 5

在where子句中,更改以下行:

if(propertyMatch) select item;
Run Code Online (Sandbox Code Playgroud)

对此:

return propertyMatch;
Run Code Online (Sandbox Code Playgroud)

如果谓词结果为true,则where子句将返回该项,因此您只需返回布尔结果.