Solved

Another property question

Posted on 2006-07-11
3
210 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 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

810 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