我是C#的新手,剛開始學習如何編寫代碼。我試圖轉換和總結一個標籤中顯示的幾個項目的金額,然後顯示在另一個標籤中的總和。我使用parse將值轉換爲double,但我經常收到一條錯誤消息,說「不能隱式轉換int類型到string.Here是我的代碼示例。如何將文本從標籤轉換爲雙重文件
int Cost;
double total = 0;
costLabel.Text = Convert.ToInt32(priceLabel2.Text);
Cost = int.Parse(priceLabel2.Text);
total += double.Parse(priceLabel2.Text);
costLabel.Text = total.ToString("c");
任何一個可以幫我解決這個問題呢?
刪除此行'costLabel.Text = Convert.ToInt32( priceLabel2.Text);'除了創建這個錯誤之外別無其他 - –
[Convert int to string?]的可能重複(https://stackoverflow.com/questions/3081916/convert-int-to-string) – DomeTune
如上所述:[string myString = myInt.ToString();](https://stackoverflow.com/a/3081919/7137009) – DomeTune