我有一個簡單的演示類這樣的...我如何添加對象到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 ... –