我不确定到底要问什么。Car
当我单击“加速”按钮时,我创建了一个名为“Form1
我希望它加速 5 个增量”的类。我需要使用 Car 类中的 Accelerate 方法来执行此操作。我以为我调用它是正确的,但没有任何效果。我需要简单的答案,因为我是初学者。
namespace Car_Class
{
class Car
{
public string _year;
public string _make;
public double _speed;
public Car(string year, string make, double speed)
{
_year = year;
_make = make;
_speed = 0;
}
public string Year
{
get { return _year; }
set { }
}
public string Make
{
get { return _make; }
set { }
}
public double Speed
{
get { return _speed; }
set { }
}
public double Accelerate()
{
return _speed += 5;
}
public double Brake()
{
return _speed -= 5;
}
}
}
然后按钮....
namespace Car_Class
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void accButton_Click(object sender, EventArgs e)
{
string _year = "";
string _make = "";
int _speed = 0;
Car acc = new Car(_year, _make, _speed);
acc.Accelerate();
currentspeedListBox.Text = ???????
}
}
}