What is difference between Field and Property. In C# how we can use the Visual Studio.Net 2003 to start a wizard which will create a property, method and field.
Thanks
Printable View
What is difference between Field and Property. In C# how we can use the Visual Studio.Net 2003 to start a wizard which will create a property, method and field.
Thanks
A "field" is a public variable. A "property" is a means to create a member that behaves like a field from the outside but like a method from the inside. A property encapsulates a "get" method and/or a "set" method. These methods can simply get and set the value of a variable if desired, or they can perform complex operations. One of the major advantages of properties is that they allow you to raise an event in the "set" method to indicate that the property value has changed. This would be impossible with a public variable. The alternative would be to do as is done in Jave and write two separate methods. The property gives you the best of both worlds. Within the class you have the two separate methods but they are hidden from view outside the class and the property appears just like a field.
In C# 2005 you can type "prop" and hit the TAB key twice to generate a private variable and corresponding public property. To the best of my knowledge this feature is not available in 2003.
By the way, you did search MSDN for information on properties and fields before asking here, didn't you?
http://lab.msdn.microsoft.com/search...siteid=0&tab=0