T
Thomas
I tried the following:
Public Class ClassA
Public Class ClassB
Private myName As String
Private myBirthday As Date
Public Property Birthday() As Date
Get
Return myBirthday
End Get
Set(ByVal Value As Date)
myBirthday = Value
End Set
End Property
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
myName = Value
End Set
End Property
End Class
Private myFriends() As ClassB
Public Sub AddFriend(ByVal Name As String, ByVal Birthday As Date)
Dim c As New ClassB
c.Name = Name
c.Birthday = Birthday
Try
ReDim Preserve myFriends(myFriends.Length)
myFriends(myFriends.Length - 1) = c
Catch ex As Exception
ReDim Preserve myFriends(0)
myFriends(0) = c
End Try
End Sub
Public Sub ShowFriends()
Dim s As String
For i As Integer = 0 To myFriends.Length - 1
s += myFriends(i).Name + " - " + myFriends(i).Birthday.ToString +
vbNewLine
Next
MessageBox.Show(s)
End Sub
Public ReadOnly Property GetFriend(ByVal Index As Integer) As ClassB
Get
Try
Return myFriends(Index)
Catch ex As Exception
Return Nothing
End Try
End Get
End Property
End Class
This testcode does not make real sense but it shows my problem.
What does VB.NET do when I declare ClassB in ClassA ? Both, ClassA and
ClassB, can be used outside with Dim c as new ClassX. So where is the
difference between declaring ClassA and ClassB as normal classes and
declaring ClassB in ClassA ?
The real problem is that I used classes in classes in a program and
that I'm not sure about the consequences of this type of coding.
Public Class ClassA
Public Class ClassB
Private myName As String
Private myBirthday As Date
Public Property Birthday() As Date
Get
Return myBirthday
End Get
Set(ByVal Value As Date)
myBirthday = Value
End Set
End Property
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
myName = Value
End Set
End Property
End Class
Private myFriends() As ClassB
Public Sub AddFriend(ByVal Name As String, ByVal Birthday As Date)
Dim c As New ClassB
c.Name = Name
c.Birthday = Birthday
Try
ReDim Preserve myFriends(myFriends.Length)
myFriends(myFriends.Length - 1) = c
Catch ex As Exception
ReDim Preserve myFriends(0)
myFriends(0) = c
End Try
End Sub
Public Sub ShowFriends()
Dim s As String
For i As Integer = 0 To myFriends.Length - 1
s += myFriends(i).Name + " - " + myFriends(i).Birthday.ToString +
vbNewLine
Next
MessageBox.Show(s)
End Sub
Public ReadOnly Property GetFriend(ByVal Index As Integer) As ClassB
Get
Try
Return myFriends(Index)
Catch ex As Exception
Return Nothing
End Try
End Get
End Property
End Class
This testcode does not make real sense but it shows my problem.
What does VB.NET do when I declare ClassB in ClassA ? Both, ClassA and
ClassB, can be used outside with Dim c as new ClassX. So where is the
difference between declaring ClassA and ClassB as normal classes and
declaring ClassB in ClassA ?
The real problem is that I used classes in classes in a program and
that I'm not sure about the consequences of this type of coding.