IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
VB.Net
Search VB.Net Group:

Advanced
-Collapse +Expand VB.Net To/From
To/FromCODEGuides
-Collapse +Expand VB.Net Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingVB.NetOOP   Print This     
  From the October 2015 Issue of Prestwood eMag
 
VB.Net OOP:
VB.Net Member Property (property, get, set)
 
Posted 16 years ago on 12/20/2008 and updated 1/28/2009
VB.Net Code Snippet:
 A flashcard from our VB.Net Flashcards Library
 A code snippet from our VB.Net Code Snippets Page

KB101741

VB.Net Member Property

VB.Net uses a special property keyword along with special get and set methods to both get and set the values of properties. For a read-only property, leave out the set method. The value keyword is used to refer to the member field. Properties can make use of any of the access modifiers (private, protected, etc).

My preference for VB.Net code is to start member fields with "F" ("FName" in our example) and drop the "F" with properties that manage member fields ("Name" in our example).

Syntax Example:
Public Class Cyborg
Private FCyborgName As String
 
  Public Property CyborgName()
Get
Return F
CyborgName
End Get
 
Set(ByVal value)
F
CyborgName = value
End Set
End Property
End Class

Complete Example

Refer to our VB.Net Class..Object post for an example.

Rumor Mill: Auto-Implemented Properties in VB.Net 10.0

It is widely rumored that the next version of VB.Net will include auto-implemented properties. Currently C# 3.0 and later offer this feature as follows:

//C# auto-implemented property.
pulic int VendorID {get; set;}

The next version of VB.Net is rumored to offer a similar syntax feature:

'VB.Net auto-implemented property.
Public Property VendorID() As Integer 

In addition, it is rumored that the next version will allow you to iniatilize the property which is something C# does not allow.

'Initialized auto-implemented properity.
Public Property VendorID() As Integer = -1

This is important and useful when no additional logic is required for a property. Soon properties will be just as easy to create as a member field and have an equivalent compact form (a single line of code).

More Info

Code:  VB.Net Class..Object (Class..End Class..New)

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1153A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101741 Counter
23877
Since 12/20/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]