# 判断两个List集合

0
[已解决问题] 解决于 2013-02-19 08:34

1

Qlin | 老鸟四级 |园豆：2403 | 2013-02-18 15:30

@淘@淘:

Qlin | 园豆：2403 (老鸟四级) | 2013-02-18 15:37

@淘@淘:  楼主的意思不是取交集吗/? Intersect 就是取两个集合的交集

havid | 园豆：70 (初学一级) | 2013-02-18 16:37

0

jerry-Tom | 园豆：4077 (老鸟四级) | 2013-02-18 15:32
0
```foreach (var item in aList)
{
var target = bList.Find(m => m.ID == item.ID);
if (target == null) continue;

bList.Remove(target);
}```
WilsonPan | 园豆：233 (菜鸟二级) | 2013-02-18 15:45

0
```    class User
{
public string Id;
public string Name;
}

private void RemoveInexistence(List<User> aList, List<User> bList)
{
if (aList != null && aList.Count > 0 && bList != null && bList.Count > 0)
{
List<User> clonedList = new List<User>();
foreach (User u in aList)
{
}

foreach (User us in clonedList)
{
User user = bList.Find(c => c.Id == us.Id);
if (user == null)
{
aList.Remove(aList.Find(c=>c.Id==us.Id));
}
}
}
}

private void Test()
{
List<User> aList = new List<User>();

User u1 = new User();
u1.Id = "1";
u1.Name = "aaa";
User u2 = new User();
u2.Id = "2";
u2.Name = "bbb";

List<User> bList = new List<User>();
User u3 = new User();
u3.Id = "3";
u3.Name = "ccc";