Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Another property question

Posted on 2006-07-11
3
Medium Priority
?
216 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 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