File tree Expand file tree Collapse file tree 2 files changed +31
-26
lines changed
docs/csharp/programming-guide/classes-and-structs/snippets/properties Expand file tree Collapse file tree 2 files changed +31
-26
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ public class Person
5151 }
5252 // </Initializer>
5353}
54+
5455namespace VersionFour
5556{
5657 // <AccessorModifiers>
@@ -76,6 +77,7 @@ public class Person
7677 }
7778 // </Readonly>
7879}
80+
7981namespace VersionSix
8082{
8183 // <InitOnly>
@@ -90,6 +92,7 @@ public Person() { }
9092 }
9193 // </InitOnly>
9294}
95+
9396namespace VersionSeven
9497{
9598 // <Required>
@@ -130,6 +133,7 @@ public Person(string firstName, string lastName)
130133 }
131134 // </ExpressionBodiedProperty>
132135}
136+
133137namespace VersionNine
134138{
135139 // <CachedBackingStore>
@@ -160,6 +164,7 @@ public string FullName
160164 }
161165 // </CachedBackingStore>
162166}
167+
163168namespace VersionTen
164169{
165170 // <UseBackingFields>
@@ -206,29 +211,29 @@ namespace properties
206211
207212 // <UsingEmployeeExample>
208213 class Employee
209- {
210- private string _name ; // the name field
211- public string Name => _name ; // the Name property
212- }
213- // </UsingEmployeeExample>
214+ {
215+ private string _name ; // the name field
216+ public string Name => _name ; // the Name property
217+ }
218+ // </UsingEmployeeExample>
214219
215- // <ManageExample>
216- class Manager
217- {
218- private string _name ;
219- public string Name => _name != null ? _name : "NA" ;
220- }
221- // </ManageExample>
220+ // <ManageExample>
221+ class Manager
222+ {
223+ private string _name ;
224+ public string Name => _name != null ? _name : "NA" ;
225+ }
226+ // </ManageExample>
222227
223- //<StudentExample>
224- class Student
225- {
226- private string _name ; // the name field
227- public string Name // the Name property
228+ //<StudentExample>
229+ class Student
228230 {
229- get => _name ;
230- set => _name = value ;
231+ private string _name ; // the name field
232+ public string Name // the Name property
233+ {
234+ get => _name ;
235+ set => _name = value ;
236+ }
231237 }
232- }
233- //</StudentExample>
238+ //</StudentExample>
234239}
Original file line number Diff line number Diff line change 44using VersionSeven ;
55
66//<GetAccessor>
7- var employee = new Employee ( ) ;
7+ var employee = new Employee ( ) ;
88//...
99
10- System . Console . Write ( employee . Name ) ; // the get accessor is invoked here
10+ System . Console . Write ( employee . Name ) ; // the get accessor is invoked here
1111//</GetAccessor>
1212
1313//<SetAccessor>
1414var student = new Student ( ) ;
15- student . Name = "Joe" ; // the set accessor is invoked here
15+ student . Name = "Joe" ; // the set accessor is invoked here
1616
17- System . Console . Write ( student . Name ) ; // the get accessor is invoked here
17+ System . Console . Write ( student . Name ) ; // the get accessor is invoked here
1818//</SetAccessor>
1919
2020HidingExample . TestHiding . Test ( ) ;
2121
2222// <SnippetInitialize>
2323var aPerson = new Person ( "John" ) ;
24- aPerson = new Person { FirstName = "John" } ;
24+ aPerson = new Person { FirstName = "John" } ;
2525// Error CS9035: Required member `Person.FirstName` must be set:
2626//aPerson2 = new Person();
2727// </SnippetInitialize>
You can’t perform that action at this time.
0 commit comments