Link to home
Start Free TrialLog in
Avatar of Confused Coder
Confused Coder

asked on

How to add multiple instance of Data class to another class

I have 2 classes similar to the 2 below where a user can have multiple emails, so how would i do this ? Would it be an array like "Private _Email As email()" or a List( of email)
and how to i add new email to the user class ?

Public Class user

Private _Fname As String = ""
Private _Mname As String = ""
Private _Lname As String = ""
Private _Email As ?? 


Public Property Fname As String
Get
Return _Fname
End Get
Set(ByVal Value As String)
_Fname = Value
End Set
End Property

Public Property Mname As String
Get
Return _Mname
End Get
Set(ByVal Value As String)
_Mname = Value
End Set
End Property

Public Property Lname As String
Get
Return _Lname
End Get
Set(ByVal Value As String)
_Lname = Value
End Set
End Property

Public Property Email As String
Get
Return _Email
End Get
Set(ByVal Value As String)
_Email = Value
End Set
End Property


End Class

Open in new window


Public Class email

Private _Nickname As String = ""
Private _Emailaddress As String = ""
Private _Default As Int32 = "0"


Public Property Nickname As String
Get
Return _Nickname
End Get
Set(ByVal Value As String)
_Nickname = Value
End Set
End Property

Public Property Emailaddress As String
Get
Return _Emailaddress
End Get
Set(ByVal Value As String)
_Emailaddress = Value
End Set
End Property

Public Property Default As Int32
Get
Return _Default
End Get
Set(ByVal Value As Int32)
_Default = Value
End Set
End Property


End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Confused Coder
Confused Coder

ASKER

Thanks, that did the job. I had it setup that way but was missing the " = New List(Of Email)" so i got an error every time i tried to add a new object.
Good stuff.

If you don't instantiate the list, then it will be Null, so trying to add to Null with give your errors.

Glad you got it sorted.