-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document init accessor #23082
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
Document init accessor #23082
Conversation
| title: "init keyword - C# Reference" | ||
| ms.date: 03/10/2017 | ||
| f1_keywords: | ||
| - "init" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidwengier Do we need this? or only init_CSharpKeyword is sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly don't need it from Roslyn's point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BillWagner The articles in the keywords folder have two entries under f1_keywords (sometimes in reverse order):
f1_keywords:
- "<keyword>_CSharpKeyword"
- "<keyword>"
Is the second entry superfluous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second entry is superfluous. Ping @ghogen to verify.
docs/csharp/language-reference/keywords/snippets/InitExample1.cs
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/keywords/snippets/InitExample1.cs
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/keywords/snippets/InitExample2.cs
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/keywords/snippets/InitExample3.cs
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,11 @@ | |||
| | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding all these new snippets under a new directory named init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. That would indeed be the prescribed pattern, but the snippets folder at present consistently follows the pattern of locating all snippets for the keywords folder directly under keywords/snippets, without separating snippets into subfolders named after articles. Rather than introduce an inconsistency here I think it better to follow the existing pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @tdykstra We agreed that both meet the standard. This is especially true in the language reference area for keywords and operators.
Co-authored-by: Youssef Victor <[email protected]>
|
Thanks for the review and corrections, @Youssef1313 ! |
BillWagner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all LGTM @tdykstra
I had a couple minor suggestions, and then this is ready to ![]()
| The class that is shown in the previous example is mutable. Client code can change the values in objects after creation. In complex classes that contain significant behavior (methods) as well as data, it's often necessary to have public properties. However, for small classes or structs that just encapsulate a set of values (data) and have little or no behaviors, you should either make the objects immutable by declaring the set accessor as [private](../../language-reference/keywords/private.md) (immutable to consumers) or by declaring only a get accessor (immutable everywhere except the constructor). For more information, see [How to implement a lightweight class with auto-implemented properties](./how-to-implement-a-lightweight-class-with-auto-implemented-properties.md). | ||
| The class that is shown in the previous example is mutable. Client code can change the values in objects after creation. In complex classes that contain significant behavior (methods) as well as data, it's often necessary to have public properties. However, for small classes or structs that just encapsulate a set of values (data) and have little or no behaviors, you should use one of the following options for making the objects immutable: | ||
|
|
||
| * Declare the `set` accessor as [private](../../language-reference/keywords/private.md) (immutable to consumers). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this to the bottom of the list, making it the least good option.
| - Declare the [set](../../language-reference/keywords/set.md) accessor to be [private](../../language-reference/keywords/private.md). The property is settable within the type, but it is immutable to consumers. | ||
|
|
||
| When you declare a private `set` accessor, you cannot use an object initializer to initialize the property. You must use a constructor or a factory method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again, I'd move these two paragraphs below the recommendation to "Declare only the get accessor, ..."
|
:D I found the new page to introduce the keyword Could you please add this keyword into the list page? Thank you! |
|
@SunnieShine This is tracked by #21603. |
|
@Youssef1313 Oh! I only found that I don't know there's an issue to describe that. Thank you for your mention! |
Fixes #20583