How to Object Array to List
Posted
by
Peter Black
on Stack Overflow
See other posts from Stack Overflow
or by Peter Black
Published on 2013-11-10T21:47:23Z
Indexed on
2013/11/10
21:53 UTC
Read the original article
Hit count: 210
(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.
© Stack Overflow or respective owner