我对C#没有太多经验,如果有人能指点一下我将不胜感激。我有一个foreach循环,引用了一个对象的变量。我希望在主循环内再创建一个foreach循环,将当前变量与对象数组中的其余变量进行比较(或执行操作)。
以下是我的代码:
// Integrate forces for each body.
foreach (RigidBodyBase body in doc.Bodies)
{
// Don't move background-anchored bodies.
if (body.anchored) continue;
// This is where we will add Each Body's gravitational force
// to the total force exerted on the object.
// For each other body, get it's point and it's mass.
// Find the gravitational force exterted between target body and looped body.
// Find distance between bodies.
// vector addition
// Force = G*mass1*mass2/distance^2
// Find vector of that force.
// Add Force to TotalGravityForce
// loop until there are no more bodies.
// Add TotalGravityForce to body.totalForce
}