Solved

Another property question

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now