Skip to content

描述勘误 #39

@PSC-F

Description

@PSC-F
  • 区别于只读属性
    与只读属性不同,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 Doe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions