我在 c# 中有两个集合
A: {
{id:4, name:"", age:1},
{id:3, name:"", age:3},
{id:2, name:"", age:5},
}
B: {
{id:2, name:"aa"},
{id:4, name:"bb"},
{id:3, name:"cc"},
}
我想根据集合 B 填充集合 A
A: {
{id:2, name:"aa",age:5},
{id:4, name:"bb",age:1},
{id:3, name:"cc",age:3},
}
我怎样才能做到这一点?(我应该使用 linq 吗?)
我用了:
private static void FillIsCpHidden(ref Collection A)
{
var B= CollectionB.ToDictionary(item => item.id);
foreach (var item in A)
{
item.name= B[item.id].name;
}
}