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