小编Beg*_*ner的帖子

C#(对象数组)对象引用未设置为对象的实例

我在这一行得到了对象引用错误:emp [count] .emp_id = int.Parse(parts [0]);

在这段代码中

这个程序从文件中读取并存储在对象数组中

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public class employees
    {
        public int emp_id;
        public string firstName;
        public string lastName;
        public double balance;
    }

    private void btnOpen_Click(object sender, EventArgs e)
    {
        OpenFileDialog file = new OpenFileDialog();
        DialogResult result = file.ShowDialog();
        if (result == DialogResult.Cancel) return;

        string fileName = file.FileName;
        StreamReader reader = new StreamReader(fileName);

        string[] lines = File.ReadAllLines(fileName);
        int emp_count = lines.Count<string>();
        employees[] emp = new employees[emp_count]; …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1