我一直在使用StreamReader inputFile
代码从一个ListBox
和它的伟大工程,但是,我想输入从数据.txt
文件转换成Label
箱代替,这可能吗? 这是我试过的代码,它给了我一个错误的描述,说明
Use of unassigned local variable 'total'
private void Form1_Load(object sender, EventArgs e)
{
try
{
int total = 0;
int highScore;
StreamReader inputFile;
inputFile = File.OpenText("HighScore.txt");
while (!inputFile.EndOfStream)
{
highScore = int.Parse(inputFile.ReadLine());
total += highScore;
}
inputFile.Close();
highscoreLabel.Text = total.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}