What am I doing wrong? The second Employee on the second to last row is what is causing this error.
`private void DisplayButton_Click(object sender, EventArgs e)
{
// clear the Employee listbox
EmployeesListBox.Items.Clear();
// read employees from the file
string fileName = "Employees.csv";
StreamReader sr = new StreamReader(fileName);
while ( sr.Peek() > -1 )
{
string line = sr.ReadLine();
string[] parts = line.Split(',');
string firstName = parts[0];
string lastName = parts[1];
string ssn = parts[2];
DateTime hireDate = DateTime.Parse(parts[3]);
Employee emp = Employee(firstName, lastName, ssn, hireDate);
EmployeesListBox.Items.Add(emp);`
}
I have rewrote my code a million times and followed my instructors instructions word for word.
2
Answers
You guys are life savers. I have had issue after issue for 4 days now. Thank you for the help.
The
Employee
class is a reference type, which means that you need to use thenew
keyword when creating a new instance.