|
-
May 20th, 2006, 08:35 PM
#1
Thread Starter
Hyperactive Member
[1.0/1.1]
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
"Visual Studio .NET 2005/.NET Framework 2.0"
The eyes are the greatest telescopes, one will ever need to study the universe. Let the heart be the tripod, the mind be the shaft, then let the eyes become the lens of that great telescope of which God gave to us all.
-
May 21st, 2006, 08:17 AM
#2
Re: [1.0/1.1]
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|