我有一个变量,并且有一些值。存储值后,我想再次清除该变量。
float t1, t2, extotal;
float e1, e2, e3, e4, e5;
private void total_button_Click(object sender, EventArgs e)
{
float.TryParse(ttb1.Text, out t1);
float.TryParse(ttb2.Text, out t2);
extotal = e1 + e2;
extrution_total_textbox.Text = extotal.ToString();
if (utb1.Text == "Bar")
{
float f = t1;
float fc = (float)Math.Round(f * 100f) / 100f;
e1 = fc;
}
if (utb2.Text == "Bar")
{
float f = t2;
float fc = (float)Math.Round(f * 100f) / 100f;
e2 = fc;
}
}
答案 0 :(得分:0)
从c#7开始(我认为是7)。你可以说:
t1 = default(float);
...
默认值为:
float - default value is 0.0f
int - default value is 0
bool - default value is false
reference type - default value is null
etc
如果您的版本不支持default
,请执行以下操作:
t1 = 0.0f;
...
或
t1 = t2 = 0.0f; ...