有更好或更有效的方法吗?
这两个对象都有相同的Id和一些我想要更新的类似字段。
foreach (var i in oldItems)
{
foreach (var j in newItemValues)
{
if(i.id == j.Id)
{
j.field1 = (decimal)i.field1;
j.field2 = (decimal)i.field2;
}
}
}
答案 0 :(得分:3)
<div class="jumbotron jumbotron-fluid">
<div class="container">
<img src="https://cdn.officialpsds.com/imageview/78/5z/785z6w_large.png?1395542934" alt="">
</div>
</div>
答案 1 :(得分:0)
在循环之前将oldItems
或newItemValues
转换为地图。
这会将计算复杂度从O(n ^ 2)降低到O(n)
答案 2 :(得分:-1)
您可以newItemsValues =
(from t1 in oldItems
join t2 in newItemsValues on t1.Id equals t2.Id
select new YourModel { field1 = t1.field1 ,field2 = t1.field2 }
).ToList();
oldItems Id
结果会列出newItemsValues Id
等于public void rightClick() {
TimerTask task;
task = new TimerTask() {
@Override
public void run() {
System.out.println("X: " + mouseConverter(mouseX) + " Y: " + mouseConverter(mouseY));
System.out.println("SX: " + select.x + " SY: " + select.y);
if (select.x != mouseConverter(mouseX) || select.y != mouseConverter(mouseY)) {
int[][] path = select.ai().getPath(arena, mouseConverter(mouseX), mouseConverter(mouseY), blocked);
select.move(path[0][0], path[0][1]);
repaint();
}
else {
cancel();
}
}
};
timer.schedule(task, 0, ANIMATION_DELAY);
}
的所有匹配项目
答案 3 :(得分:-1)
capabilites
如果您想从newItemValues = (from a in oldItems
join b in newItemValues on a.id equals b.id
select new YourClass() {field1 = b.field1 ... }).ToList();
select b
当然,您必须添加b