Initialization of classes with a constructor in C#
Forums:
var nokiaPhone = new Phone("Nokia 6610");
var kim = new Employee("Victorya", "Kim",
new Phone("iPhone 5"));
class Phone {
public string Model { get; set; }
public Phone(string model) {
Model = model;
}
}
class Employee {
public string FirstName { get; set; }
public string LastName { get; set; }
public Phone PersonalPhone { get; set; }
public Employee(string firstName, string lastName, Phone personalPhone) {
FirstName = firstName;
LastName = lastName;
PersonalPhone = personalPhone;
}
}
- Log in to post comments