Shorthand for Property declaration in VB

D

David W

I have a very simple class that just stores a number of strings so I can use
them in an ArrayList bound to a Repeater. There is no validation or
calculations needed for the properties. Is there any shorthand for this
without having to define a Property and a Get for every single instance
variable? This gets very old when you have many properties (30+). If I
just declare the instance vars as public (renaming them without the my) and
provide no Property accessor, the Repeater can't access them as it
enumerates. It just seems like an excessive amount of code for something so
simple.

Public Class SimpleClass
Private myName, myLabel As String

Public Sub New(ByVal Name As String, ByVal Label As String)
Me.myName = Name
Me.myLabel = Label
End Sub

Public ReadOnly Property Name() As String
Get
Return Me.myName
End Get
End Property

Public ReadOnly Property Label() As String
Get
Return Me.myLabel
End Get
End Property
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top