1

我有一段代码:

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;
    });

如果条件匹配,我希望选择该项目。但是,我收到错误:

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

有什么建议么!

4

1 回答 1

5

在 where 子句中,更改此行:

if(propertyMatch) select item;

对此:

return propertyMatch;

如果谓词结果为真,where 子句将返回项目,因此您只需要返回布尔结果。

于 2013-02-25T00:09:40.557 回答