?
Solved

Another property question

Posted on 2006-07-11
3
Medium Priority
?
217 Views
Last Modified: 2010-04-23
Can I have a property that contained an array?

For instance, if I have Group
consisting of Person1, Person2, etc.

Could I have

Public Property Group() as Array
Get
  Return myGroup
End Get
Set (ByVal Value As Array)
  myGroup=Value
End Set
End Property
0
Comment
Question by:sirbounty
3 Comments
 
LVL 24

Assisted Solution

by:Jeff Certain
Jeff Certain earned 200 total points
ID: 17087246
If you're using VB2005, use System.Collections.Generic.List(of Person)

This is essentially a typesafe array.

Public Property People() As List(of Person)
Get
  Return myGroup
End Get
Set (ByVal Value As List(of person))
  myGroup=Value
End Set
End Property

In any case, you can create properties for any type of object, including array, hashtable, string, integer, object, stringbuilder, and anything else you can think of.
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 300 total points
ID: 17087334
Hi sirbounty;

In answer to your question, Yes. It can be of any type as well as arrays. The sample code below will show how to implement it.

' Person class
Public Class Person
    Public FirstName As String
    Public LastName As String
End Class

' Class1 stores Person array
Public Class Class1

    Dim myGroup(2) As Person

    Public Property Group() As Person()
        Get
            Return myGroup
        End Get
        Set(ByVal Value As Person())
            myGroup = Value
        End Set
    End Property

End Class


'Code in main which creates a Class1 and Person array to be stored
        Dim mc As New Class1
        Dim pArray(2) As Person
        Dim p As Person
        p = New Person
        p.FirstName = "John"
        p.LastName = "Doe"
        pArray(0) = p
        p = New Person
        p.FirstName = "Tom"
        p.LastName = "Smith"
        pArray(1) = p
        mc.Group = pArray
        p = New Person
        p.FirstName = "Fernando"
        p.LastName = "Soto"
        pArray(2) = p
        mc.Group = pArray

        ' Get the array and print it out
        For Each p In mc.Group
            Console.WriteLine("First Name: " & p.FirstName & " " & _
                "Last Name: " & p.LastName)
        Next


Hope that this was of some help.

Fernando
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17093152
For this one - I'm going to have to use 2003...
A bit beyond me though, I'm afraid...
Thanx.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question