1: class Customer
2: {
3: private string _FirstName;
4: private string _LastName;
5:
6: public string FirstName
7: {
8: get
9: {
10: return _FirstName;
11: }
12: set
13: {
14: _FirstName = value;
15: }
16: }
17: public string LastName
18: {
19: get
20: {
21: return _LastName;
22: }
23: set
24: {
25: _LastName = value;
26: }
27: }
28: }
A pretty straight forward customer class with two properties ( FirstName, LastName ). Now with automatic properties, the same code can be compressed down to fewer lines. When the compiler encounters code like the following, it will automate the generation of the private fields along with get and set method. This lets the developer write fewer lines of code up front and follow good class design. Later on, if needed, the developer can put custom getter/setter code without having to recompile the consuming assembly.
3: public string FirstName { get; set; }
4: public string LastName { get; set; }
5: }
The last information I've heard is that this as a C# only feature. I haven't heard of anything similar for VB.NET at this time.
Remember Me
Page rendered at Thursday, August 28, 2008 10:11:35 PM (Eastern Standard Time, UTC-05:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.