How to Add items to Generic List Error
i am getting error "Object reference not set to an instance of an object."
public class Employee {
public string Name { get; set; }
public List<EmployeeDepartments> EmployeeDetails { get; set; }
}
public class EmployeeDepartments {
public string Department { get; set; }
public int Mark { get; set; }
}
private void Form1_Load(object sender, EventArgs e) {
List<Employee> employees = new List<Employee>();
try
{
Employee emp = new Employee();
emp.Name = "a";
EmployeeDepartments dept = new EmployeeDepartments();
dept.Department = "IT";
dept.Mark = 100;
emp.EmployeeDetails.Add(dept);
employees.Add(emp);
}
catch(Exception ex) {
}
}