Array in a property

  • Thread starter Thread starter Q
  • Start date Start date
Q

Q

Hello to the pro's,

I want to use an array in a class. This array should be visible as a
property.
Just can't seem to find out how to do it.
Maybe there are other (and more easy) solutions?
Can anyone help me??

Regards,

Q
 
Q said:
Hello to the pro's,

I want to use an array in a class. This array should be visible as a
property.
Just can't seem to find out how to do it.
Maybe there are other (and more easy) solutions?
Can anyone help me??

Regards,

Either make the Array a Public Readonly field, or:

Private f_Items(17) As Integer

Public Property Item(ByVal Index As Integer) As Integer
Get
Return f_Items(Index)
End Get
Set(ByVal value As Integer)
f_Items(Index) = value
End Set
End Property


Armin
 
you probably need something like:

Public MyArray() As String

Public MyList() As List(Of String)

second is much better. If you also need set/get (less common)
implement it as a "property".
"String" can be replaced with any type.



Tommaso
 
Hello to the pro's,

I want to use an array in a class. This array should be visible as a
property.
Just can't seem to find out how to do it.
Maybe there are other (and more easy) solutions?
Can anyone help me??

-------------

The array or arraylist should be Private

But the Property Get and Set for an item of the array should be Public.

You'll see the example in the links

http://www.developerfusion.co.uk/show/1047/2/
http://www.java2s.com/Code/VB/Data-Structure/UseArrayListtoStoreyourownclass.htm
 
Back
Top