Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

描述勘误 #39

Open
PSC-F opened this issue Aug 20, 2024 · 0 comments
Open

描述勘误 #39

PSC-F opened this issue Aug 20, 2024 · 0 comments

Comments

@PSC-F
Copy link

PSC-F commented Aug 20, 2024

  • 区别于只读属性
    与只读属性不同,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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant