Home
Manage Your Code
Snippet: C# Set / Get (C#)
Title: C# Set / Get Language: C#
Description: Using properties Views: 1044
Author: Rikesh Kisnah Date Added: 11/25/2011
Copy Code  
1using System;
2
3public class Customer
4{
5    private int m_id = -1;
6
7    public int ID
8    {
9        get
10        {
11            return m_id;
12        }
13        set
14        {
15            m_id = value;
16        }
17    }
18
19    private string m_name = string.Empty;
20
21    public string Name
22    {
23        get
24        {
25            return m_name;
26        }
27        set
28        {
29            m_name = value;
30        }
31    }
32}
33
34public class CustomerManagerWithProperties
35{
36    public static void Main()
37    {
38        Customer cust = new Customer();
39
40        cust.ID = 1;
41        cust.Name = "Amelio Rosales";
42
43	Console.WriteLine(
44            "ID: {0}, Name: {1}",
45            cust.ID,
46            cust.Name);
47
48        Console.ReadKey();
49    }
50
Notes
http://www.csharp-station.com/Tutorials/Lesson10.aspx