【发布时间】:2010-11-01 01:33:31
【问题描述】:
我正在学习写 lambda expressions,我需要有关如何从一个列表中删除不在另一个列表中的所有元素的帮助。
var list = new List<int> {1, 2, 2, 4, 5};
var list2 = new List<int> { 4, 5 };
// Remove all list items not in List2
// new List Should contain {4,5}
// The lambda expression is the Predicate.
list.RemoveAll(item => item. /*solution expression here*/ );
// Display results.
foreach (int i in list)
{
Console.WriteLine(i);
}
【问题讨论】: