我有一个简单的演示类这样的...我如何添加对象到ICollection的<>对象
员工
public class Employee
{
public string Name { get; set; }
public string Email { get; set; }
}
一个多类AddressDetails
public class AddressDetails
{
public string Address1 { get; set; }
public string City { get; set; }
public string State { get; set; }
}
一个更多EmpAdd
public class EmpAdd
{
public ICollection<Employee> Employees { get; set; }
public ICollection<AddressDetails> AddressDetails { get; set; }
}
o K,当我路过的一些值类这样的..
Employee newEmp = new Employee();
newEmp.Email = "[email protected]";
newEmp.Name = "Judy";
AddressDetails newAddress = new AddressDetails();
newAddress.Address1 = "UK";
newAddress.City = "London";
newAddress.State = "England";
一切工作正常...
,但是当我试图在EmpAdd添加这两它给我的错误“未将对象引用设置为实例”请帮助...这只是一个虚拟的..我有,我现在面临同样的问题,7个实体....
EmpAdd emp = new EmpAdd();
emp.Employee.Add(newEmp);
emp.AddressDetails.Add(newAddress);
这真是太棒了.... thx ... –