Results 1 to 2 of 2

Thread: [1.0/1.1]

  1. #1

    Thread Starter
    Hyperactive Member ahmad_iam's Avatar
    Join Date
    Jun 2005
    Location
    Pakistan
    Posts
    265

    Exclamation [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width