我有一段代码:
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;
});
如果条件匹配,我想要选择该项目。但是,我收到错误:
嵌入式声明不能是声明或带标签的声明
任何建议!
答案 0 :(得分:5)
在你的where子句中,更改以下行:
if(propertyMatch) select item;
对此:
return propertyMatch;
如果谓词结果为true,则where子句将返回该项,因此您只需要返回布尔结果。