真是个愚蠢的问题,因为我认为你做不到,但是
namespace Parking_Ticket_Fines
{
public partial class frmParking : Form
{
public frmParking()
{
InitializeComponent();
}
private void btnCal_Click(object sender, EventArgs e)
{
//Variable
int Total = 0;
//Checks which radio button is checked
if (radExpired.Checked)
{
Total = 35;
}
else if (radParking.Checked)
{
Total = 75;
}
else if (radDriveway.Checked)
{
Total = 150;
}
else if (radHandicap.Checked)
{
Total = 500;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
//Clears everything
lblTotal.Text = "";
radRepeat.Checked = false;
radExpired.Checked = true;
}
有没有一种方法可以在两个私有(private)空隙中使用“Total”变量而无需声明两次?
Is there a way I can use the "Total" variable in both private voids without declaring it in twice?
是的,在类级别声明它。
public partial class frmParking : Form
{
private int Total; //Here
public frmParking()
{
InitializeComponent();
}
Total
将是一个字段阅读更多关于 Fields (C# Programming Guide)
我是一名优秀的程序员,十分优秀!