0

I have two lists of objects, and I have been learning how to remove items from one list if they appear in another.

I have come up with this:

result.ResultantPoliciesTable.RemoveAll(item => result.PoliciesTable.Select
(f => f.PolicyName).Contains(item.PolicyName));

This works, but if an integer property of the object in ResultantPoliciesTable called ManagementID equals a value I will supply then I do not want this object to be removed.

Can anyone help me extend this query to achieve this?

4

2 に答える 2

3

次のことを試してください。

int doNotRemoveID = 7862384732;
result.ResultantPoliciesTable.RemoveAll(
    item => item.ManagementID != doNotRemoveID && 
            result.PoliciesTable.Select(f => f.PolicyName).Contains(item.PolicyName));

変数itemには からの各レコードが入力されResultantPoliciesTable、結果のメソッドが を返す場合true、それは削除されます。したがって、item.ManagementID除外する必要があるかどうかを確認するチェックを追加するだけで、ニーズを満たすのに十分なはずです。

于 2013-04-15T11:13:59.033 に答える
0
result.ResultantPoliciesTable
      .RemoveAll(item => 
                      result.PoliciesTable
                            .Where(i => i.ManagementID!=myId)
                            .Select(f => f.PolicyName)
                            .Contains(item.PolicyName)
                );
于 2013-04-15T11:18:09.920 に答える