[Solved] How to create an Address field into this Company class [closed]


You almost have it. You just need to require an Address in your constructors and set a corresponding property with that passed in address.

public class Address
{
    public string Street { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }

    public Address(string street, string city, string state, string zipCode)
    {
        Street = street;
        City = city;
        State = state;
        ZipCode = zipCode;
    }
}

public class Customer
{
    public long Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Address Address { get; set; }

    public Customer(long id, string firstName, string lastName, Address address)
    {
        Id = id;
        FirstName = firstName;
        LastName = lastName;
        Address = address;
    }


}

public class Company
{
    public string CompanyName { get; set; }
    public Address Address { get; set; }

    public Company(string companyName, Address address)
    {
        CompanyName = companyName;
        Address = address;
    }
}

Then your desired code will work:

var address = new Address("56 Main St", "Mesa", "AZ", "38574");
var customer = new Customer("John", "Doe", address);
var company = new Company("Google", address);

solved How to create an Address field into this Company class [closed]