How to Object Array to List
- by Peter Black
(C#) I have 2 classes. 1 is called Employee. The other is my "main". I am trying to take a list and assign each value in list to an array of Employee object.
//Inside "Main" class
int counter = NameList.Count;
Employee[] employee = new Employee[counter];
for (int i = 0; i <= counter; i++)
{
employee[i].Name = NameList[i];
employee[i].EmpNumber = EmpNumList[i];
employee[i].DateOfHire = DOHList[i];
employee[i].Salary = SalaryList[i];
employee[i].JobDescription = JobDescList[i];
employee[i].Department = DeptList[i];
}
This returns the error:
An unhandled exception of type 'System.NullReferenceException' occurred in Pgm4.exe
Additional information: Object reference not set to an instance of an object.
I think this means that I am not calling the list properly. Any help would be much appreciated. Thank you.