-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPropertiesExpression.cs
More file actions
40 lines (35 loc) · 947 Bytes
/
PropertiesExpression.cs
File metadata and controls
40 lines (35 loc) · 947 Bytes
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
/*
* Properties in C# are members of a class that provide a flexible mechanism to read, write, or compute the values of private fields.
* It is a way to expose private fields of a class and to control the access to them.
*/
using System;
namespace Basics
{
class PropertiesExpression
{
class Props
{
private int id;
private string name;
public int Id
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
}
public void Example()
{
Props p = new Props();
// Setting the values
p.Id = 1;
p.Name = "John";
// Displaying the values
Console.WriteLine("Id: {0}, Name: {1}", p.Id, p.Name);
}
}
}