public void button1_Click(object sender, EventArgs e)
{
if (cushioncheckBox.Checked)
{
decimal totalamtforcushion = 0m;
totalamtforcushion = 63m * cushionupDown.Value;
string cu = totalamtforcushion.ToString("C");
cushioncheckBox.Checked = false;
cushionupDown.Value = 0;
}
if (cesarbeefcheckBox.Checked)
{
decimal totalamtforcesarbeef = 0m;
totalamtforcesarbeef = 1.9m * cesarbeefupDown.Value;
string cb = totalamtforcesarbeef.ToString("C");
cesarbeefcheckBox.Checked = false;
cesarbeefupDown.Value = 0;
}
}
所以我有這些代碼。我如何將兩個字符串cb和cu加在一起?我試過如何將字符串添加到一起?
decimal totalprice;
totalprice = cu + cb;
但它說名稱在上下文中不存在。 我該怎麼辦?
我使用Windows形成順便說一句
爲什麼你使用字符串變量,如果你執行數學? – Derek
在你的'if'語句之外聲明你的字符串。和字符串!=小數,你將需要轉換它們。 – PhoenixReborn
,因爲我想把總值放在文本框中! – user2037510