誰猜猜誰回來! 程序運行(horrah),但現在變量不保存該值。 的主要形式有:C#(再次,再次?)變量不保存
Airplane plane = new Airplane();
private void btnAccel_Click(object sender, EventArgs e)
{
lblStatus.Text = plane.speed.ToString();
plane.speed = double.Parse(txtSpeed.Text);
plane.Accelerate();
lblStatus.Text = plane.speed.ToString();
}
而且從類飛機:
class Airplane
{
private string name{get; set;}
private Position PlanePosition;
private static int numberCreated;
public Airplane()
{
this.PlanePosition = new Position();
}
public void Accelerate()
{
// increase the speed of the airplane
if (PlanePosition.speed < Position.MAX_SPEED)
{
PlanePosition.speed +=1; // or speed += 1;
}//end of if
numberCreated++; // increment the numberCreated each time an Airplane object is created
}
「位置」 是另一個類:
class Position
{
internal int x_coordinate;
internal int y_coordinate;
internal double speed;
internal int direction;
internal const int MAX_SPEED = 50;
public Position()
{
}
public string displayPosition()
{
return "okay";
}
}
,由於某種原因,從文本框的變量主窗體進入「速度」變量,但飛機類中的速度變量沒有該變量。
什麼是`plane.speed`?我看到你指定了它,但我沒有看到它的存儲位置或使用位置。 – 2011-01-20 16:53:11
我在'飛機'上看不到'速度'屬性或者字段' – 2011-01-20 16:53:56