我想添加速度列表,但我沒有意識到這樣做時,列表中的變量會改變,當我希望他們作爲常量。有人有主意嗎?非常感謝。列表:如何添加常量類
我的代碼
void CalculateVelocity(List<velocity> ListOfVelocity, particle newprojectile, Environment newEnvironment)
{
//load in stats
newEnvironment.gravity = -9.8;
newprojectile.TimeOfFlight = Convert.ToDouble(txtbox_TimeOfFlight.Text);
newprojectile.InitialVelocity.Magnitude = Convert.ToDouble(txtbox_InitialVelocity.Text);
newprojectile.InitialVelocity.AngleOfTravel = Convert.ToDouble(txtb_AngleOLaunch.Text);
double TimeInterval;
double FlightTime =0;
double InitialHVelocity;
velocity newVelocity;
newVelocity = new velocity();
newVelocity.Magnitude = Convert.ToDouble(txtbox_InitialVelocity.Text);
newVelocity.AngleOfTravel = Convert.ToDouble(txtb_AngleOLaunch.Text);
newVelocity.AngleOfTravel = newprojectile.InitialVelocity.AngleOfTravel;
velocity.CalculateVComponent(newVelocity);
velocity.CalculateHComponent(newVelocity);
InitialHVelocity = newVelocity.HorizontalVelocity;
ListOfVelocity.Add(newVelocity);
if (newprojectile.TimeOfFlight > 60)
{
TimeInterval = newprojectile.TimeOfFlight/60;
}
else
{
TimeInterval = 1;
}
FlightTime =FlightTime+ TimeInterval;
while (!(newprojectile.TimeOfFlight < FlightTime))
{
velocity.CalculateVComponent(newVelocity, FlightTime, newEnvironment, newVelocity.VerticleVelocity);
ListOfVelocity.Add(newVelocity);
FlightTime = FlightTime + TimeInterval;
}
}
好問題,但請提供一個[*最小*代碼示例](http://stackoverflow.com/help/mcve)再現問題。 – Heinzi 2014-12-06 12:06:51