Using the Properties and Property Attributes
The simple class shown in Listing 3.6.1 has properties.
Listing 3.6.1. The SimpleObject Class
1: public class SimpleObject 2: { 3: private int _int; 4: private string _string; 5: private Color _color; 6: 7: public SimpleObject() 8: { 9: // 10: // TODO: Add constructor logic here 11: // 12: } 13: 14: public int TheInteger 15: { 16: get 17: { 18: return _int; 19: } 20: set 21: { 22: _int=value; 23: } 24: } 25: 26: public string TheString 27: { 28: get 29: { 30: return _string; 31: } 32: set 33: { 34: _string=value; 35: } 36: } 37: 38: public Color TheColor 39: { 40: get 41: { 42: return _color; 43: } 44: set 45: { 46: _color=value; 47: } 48: } 49: } |
You can see that the class has three private data ...
Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.