我有一个带有一些数字的.txt文件
File:
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
我想有一个方法来读取这些数字并将它们添加到列表或数组中,它将在消息框中显示它.
我现在有这个:
public void LaadVrijeKamers()
{
int KamerNummers = Convert.ToInt32(File.ReadAllText(@"x\Vrijekamers.txt"));
MessageBox.Show(Convert.ToString(KamerNummers));
}
Run Code Online (Sandbox Code Playgroud)
我在荷兰语中收到错误,说明如下:
Can not read the characters
Run Code Online (Sandbox Code Playgroud)
我认为File.ReadAllText仅适用于Strings,但我不确定.也许我转错了.
尝试逐行阅读并将字符串转换为整数:
var numbers = File.ReadLines(@"C:\path\numbers.txt").Select(int.Parse).ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
101 次 |
| 最近记录: |