这些是来自文本文件
的值
1245.67
1189.55
1098.72
1456.88
2109.34
1987.55
1872.36
它们显然是十进制数字
我不确定我漏掉了什么,但当我调试时会出现“输入字符串格式不正确”的错误提示,请帮我看看。
这是我目前编写的代码:
private void getValuesButton_Click(object sender, EventArgs e)
{
try
{
//create an array to hold items read from the file.
const int SIZE = 7;
double[] numbers = (double[])ois.readObject();
// Counter variable to use in the loop
int index = 0;
//Declare a StreamReader variable
System.IO.StreamReader inputFile;
//Open the file and get a StreamReader object.
inputFile = File.OpenText("Values.txt");
//Read the file contents into the array.
while (index < numbers.Length && !inputFile.EndOfStream)
{
numbers[index] = int.Parse(inputFile.ReadLine());
index++;
}
//Close the file.
inputFile.Close();
//Display the array elements in the list box.
foreach (double value in numbers)
{
outputListbox.Items.Add(value);
}
}
catch (Exception ex)
{
//Display an error message.
MessageBox.Show(ex.Message);
}