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
51
51
}
52
52
// </Initializer>
53
53
}
54
+
54
55
namespace VersionFour
55
56
{
56
57
// <AccessorModifiers>
@@ -76,6 +77,7 @@ public class Person
76
77
}
77
78
// </Readonly>
78
79
}
80
+
79
81
namespace VersionSix
80
82
{
81
83
// <InitOnly>
@@ -90,6 +92,7 @@ public Person() { }
90
92
}
91
93
// </InitOnly>
92
94
}
95
+
93
96
namespace VersionSeven
94
97
{
95
98
// <Required>
@@ -130,6 +133,7 @@ public Person(string firstName, string lastName)
130
133
}
131
134
// </ExpressionBodiedProperty>
132
135
}
136
+
133
137
namespace VersionNine
134
138
{
135
139
// <CachedBackingStore>
@@ -160,6 +164,7 @@ public string FullName
160
164
}
161
165
// </CachedBackingStore>
162
166
}
167
+
163
168
namespace VersionTen
164
169
{
165
170
// <UseBackingFields>
@@ -206,29 +211,29 @@ namespace properties
206
211
207
212
// <UsingEmployeeExample>
208
213
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>
214
219
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>
222
227
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
228
230
{
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
+ }
231
237
}
232
- }
233
- //</StudentExample>
238
+ //</StudentExample>
234
239
}
Original file line number Diff line number Diff line change 4
4
using VersionSeven ;
5
5
6
6
//<GetAccessor>
7
- var employee = new Employee ( ) ;
7
+ var employee = new Employee ( ) ;
8
8
//...
9
9
10
- System . Console . Write ( employee . Name ) ; // the get accessor is invoked here
10
+ System . Console . Write ( employee . Name ) ; // the get accessor is invoked here
11
11
//</GetAccessor>
12
12
13
13
//<SetAccessor>
14
14
var student = new Student ( ) ;
15
- student . Name = "Joe" ; // the set accessor is invoked here
15
+ student . Name = "Joe" ; // the set accessor is invoked here
16
16
17
- System . Console . Write ( student . Name ) ; // the get accessor is invoked here
17
+ System . Console . Write ( student . Name ) ; // the get accessor is invoked here
18
18
//</SetAccessor>
19
19
20
20
HidingExample . TestHiding . Test ( ) ;
21
21
22
22
// <SnippetInitialize>
23
23
var aPerson = new Person ( "John" ) ;
24
- aPerson = new Person { FirstName = "John" } ;
24
+ aPerson = new Person { FirstName = "John" } ;
25
25
// Error CS9035: Required member `Person.FirstName` must be set:
26
26
//aPerson2 = new Person();
27
27
// </SnippetInitialize>
You can’t perform that action at this time.
0 commit comments