Solved

Another property question

Posted on 2006-07-11
3
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Assisted Solution

by:Jeff Certain
Jeff Certain earned 50 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 63

Accepted Solution

by:
Fernando Soto earned 75 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

Independent Software Vendors: 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

705 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