में मुझे सी # के साथ बहुत अधिक अनुभव नहीं है, इसलिए यदि कोई मुझे सही दिशा में इंगित कर सकता है तो मैं इसकी सराहना करता हूं। मेरे पास एक फ़ोरैच लूप है जो किसी ऑब्जेक्ट के चर का संदर्भ देता है। मैं मुख्य चर के अंदर एक और फ़ोरैच लूप बनाना चाहता हूं जो ऑब्जेक्ट की सरणी में शेष चर के लिए वर्तमान चर की तुलना करता है (या क्रियाएं करता है)। मैं निम्नलिखित कोड है:सी # फोरैच लूप
// 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
}
मुझे यह जवाब सबसे अच्छा लगता है क्योंकि, मैंने जो पढ़ा है, उससे फोरच लूप लूप के लिए अधिक कुशल है। – wcm