코드 2-3 불변 클래스 예제
class ConferenceRegistration{
public string CampaignSource { get; private set; } public string FirstName { get; private set; } public string? MiddleName { get; private set; } public string LastName { get; private set; } public string Email { get; private set; } public DateTimeOffset CreatedOn { get; private set; } = DateTime.Now;
→ 모든 속성은 private set을 갖는다.
public ConferenceRegistration(
string firstName,
string? middleName,
string lastName,
string email,
string? campaignSource = null) { → 널로 옵션을 나타낸다.
FirstName = firstName;
MiddleName = middleName;
LastName = lastName;
Email = email;
CampaignSource = campaignSource ?? "organic";
}
}