-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
- 区别于只读属性
与只读属性不同,Init only setters 的值可以在对象初始化之后更改。以下是一个示例:[勘误:这里不可以修改]
public class Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
public string FullName => $"{FirstName} {LastName}";
}
var person = new Person
{
FirstName = "John",
LastName = "Doe"
};
Console.WriteLine(person.FullName); // Output: John Doe
person.FirstName = "Jane";
person.LastName = "Doe";
Console.WriteLine(person.FullName); // Output: Jane DoeReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels