我需要对两个列表的 X 和 Y 字段求和,但第一个 ID 等于第二个 ID。
我的代码:
//Program.cs
//(...)
class Point
{
public int Id { get; set; }
public int X { get; set; }
public int Y { get; set; }
public Point(int _Id, int _X, int _Y)
{
Id = _Id;
X = _X;
Y = _Y;
}
}
//(...)
List<Point> points = new List<Point>();
List<Point> sumsXY = new List<Point>();
//sum the X and Y of two lists, but points.Id must equal to sumsXY.Id
for (int i = 0; i < objcount; i++)
{
sumsXY[points[i].Id].X = sumsXY[points[i].Id].X + points[i].X;
sumsXY[points[i].Id].Y = sumsXY[points[i].Id].Y + points[i].Y;
}
需要帮忙。
大卫