【发布时间】:2017-01-02 19:22:27
【问题描述】:
public static List<TDuplicate> ValidateColumnInList<TItem, TDuplicate>(List<TDuplicate> DuplicateExpression) where TDuplicate : DuplicateExpression
{
List<TDuplicate> TempDuplicateExpression = new List<TDuplicate>();
var itemProperties = typeof(TItem).GetProperties();
foreach (var DplExpression in DuplicateExpression)
{
bool IsContainColumn = itemProperties.Any(column => column.Name == DplExpression.ExpressionName);
if (!IsContainColumn)
{
TempDuplicateExpression.Add(DplExpression);
}
}
return TempDuplicateExpression;
}
在上面的部分中如何将上面的foreach替换为linq ForEach。
【问题讨论】:
-
你有点误解,Linq 是一种用于选择数据的查询语言,它没有 ForEach,List 类确实有 for each 以及 Parallel 类,但它们都不是 Linq