forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
103 lines (91 loc) · 2.23 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
namespace Properties
{
//<Snippet1>
class Person
{
private string _name = "N/A";
private int _age = 0;
// Declare a Name property of type string:
public string Name
{
get
{
return _name;
}
set
{
//<Snippet4>
_name = value;
//</Snippet4>
}
}
// Declare an Age property of type int:
public int Age
{
get
{
return _age;
}
set
{
_age = value;
}
}
//<Snippet6>
public override string ToString()
{
return "Name = " + Name + ", Age = " + Age;
}
//</Snippet6>
}
public class Wrapper
{
private string _name = "N/A";
//<Snippet2>
public string Name
{
get
{
return _name;
}
private set
{
//<Snippet4>
_name = value;
//</Snippet4>
}
}
//</Snippet2>
}
class TestPerson
{
static void Main()
{
// Create a new Person object:
Person person = new Person();
// Print out the name and the age associated with the person:
Console.WriteLine($"Person details - {person}");
// Set some values on the person object:
//<Snippet3>
person.Name = "Joe";
person.Age = 99;
//</Snippet3>
Console.WriteLine($"Person details - {person}");
// Increment the Age property:
//<Snippet5>
person.Age += 1;
//</Snippet5>
Console.WriteLine($"Person details - {person}");
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
/* Output:
Person details - Name = N/A, Age = 0
Person details - Name = Joe, Age = 99
Person details - Name = Joe, Age = 100
*/
//</Snippet1>
}