Basically what I am trying to do is add a customer in a customer list, in the customer list there is a property BillToContact. I would like to create an instance BillToContact for a customer.
public class Customer
{
public string ID { get; set; }
public string AccountName { get; set; }
public Contact BillToContact { get; set; }
}
public class BillToContact
{
public string firstname { get; set; }
public string LastName { get; set; }
}
public class Contact
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
// Below is attempt to add BillToContact to Customer
public void test()
{
List<Customer> Customer = new List<Customer>();
Customer x = new Customer();
x.ID = "MyId";
x.AccountName = "HelloAccount";
x.BillToContact.FirstName = "Jim";
x.BillToContact.LastName = "Bob";
Customer.Add(x);
}
The error for this attempt was an
Object reference not set to an instance of an object.
I have also tried to create a instance of BillToContact
inside of Customer
to no success. To avoid any confusion, The issue is that I am trying to make a instance if BillToContact inside the Customer list.