You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
区别于只读属性
与只读属性不同,Init only setters 的值可以在对象初始化之后更改。以下是一个示例:[勘误:这里不可以修改]
publicclassPerson{publicstringFirstName{get;init;}publicstringLastName{get;init;}publicstringFullName=>$"{FirstName}{LastName}";}varperson=newPerson{FirstName="John",LastName="Doe"};Console.WriteLine(person.FullName);// Output: John Doeperson.FirstName="Jane";person.LastName="Doe";Console.WriteLine(person.FullName);// Output: Jane Doe
The text was updated successfully, but these errors were encountered:
与只读属性不同,Init only setters 的值可以在对象初始化之后更改。以下是一个示例:[勘误:这里不可以修改]
The text was updated successfully, but these errors were encountered: