这是一个菜鸟问题,我很抱歉。我一直在尝试弄清楚如何将对象添加到该数组中。我有一个 Employee 类,一个从 Emp 继承的 Salary 类,以及一个 Hourly 类。我创建了一个这样的数组,
public Employee[] _Employees;
...
Employee[] _Employees = new Employee[]{
new Hourly("1000", "Harry","Potter", "L.", "Privet Drive", "201-9090", "40.00", "12.00"),
new Salary("2201", "A.", "A.", "Dumbledore", "Hogewarts", "803-1230", "1200"),
new Hourly("3330", "R.","Weasley", "R.", "The Burrow", "892-2000", "40", "10.00"),
new Salary("4040", "R.", "R.", "Hagrid", "Hogwarts", "910-8765", "1000")
};
现在我想将对象添加到从文本文件中读取的数组中。我现在正在这样做;
if(rstring == "H")
{
string fullName = data.ReadLine();
string empNum = data.ReadLine();
string address = data.ReadLine();
string phoneNum = data.ReadLine();
string hrWorked = data.ReadLine();
string hrRate = data.ReadLine();
string[] splitName = fullName.Split(new Char[] { ' ' });
string fName = splitName[0];
string mName = splitName[1];
string lName = splitName[2];
_MyForm._Employees = new Employee[] {new Hourly ( empNum, fName, mName, lName, address, phoneNum, hrWorked, hrRate ) };
这并没有给我任何错误,但是当我查看 _Employees 类中存储的内容时,它只有上面的信息,没有其他信息。如果我需要更好地解释自己,请告诉我。只要让我知道我是否需要以另一种方式去做,或者我需要做什么才能将读取信息添加到这个 _Employees 类。