M
Martin Horn
Hi group.
I have implemented a class along these lines,
Public Class CustomerDetails
Private fRecordString As String
Public Sub New(ByVal RecordString As String)
fRecordString = RecordString
End Sub
Public ReadOnly Property CustomerNumber() As String
Get
Dim Parts() As String
If fRecordString = "" Then Return ""
Parts = Split(fRecordString, vbCrLf)
Return Parts(C_NUMBER)
End Get
End Property
Public ReadOnly Property Name() As String
Get
Dim Parts() As String
Dim s As String
If fRecordString = "" Then Return ""
Parts = Split(fRecordString, vbCrLf)
If Parts(C_TITLE) <> "" Then s = Parts(C_TITLE) + " "
If Parts(C_FORENAME) <> "" Then s = s + Parts(C_FORENAME) + " "
If Parts(C_SURNAME) <> "" Then s = s + Parts(C_SURNAME)
Return s
End Get
End Property
End Class
I then use this code elsewhere in my program,
Dim en As IEnumerator = Records.GetEnumerator
While en.MoveNext
' Add each name to the Name list
lstNames.Items.Add(New CustomerDetails(en.Current.ToString).Name)
End While
This works exactly as I want, I used the parameterised constructer to pass
a string to the class, which then uses the name property to return a
formatted string all in one neat line of code.
The question I am (finally) asking is, is this creating a memory leak as I
am creating new instances of the class with no obvious way of disposing
of them, or will this be taken care of by the garbage collector? Also,
would this be classed as bad programming style.
As you can probably tell I am new to VB.NET having come from
a VB6 background and I haven't yet quite got my head around the
new programming features.
Thanks for your time,
Regards,
Martin Horn.
I have implemented a class along these lines,
Public Class CustomerDetails
Private fRecordString As String
Public Sub New(ByVal RecordString As String)
fRecordString = RecordString
End Sub
Public ReadOnly Property CustomerNumber() As String
Get
Dim Parts() As String
If fRecordString = "" Then Return ""
Parts = Split(fRecordString, vbCrLf)
Return Parts(C_NUMBER)
End Get
End Property
Public ReadOnly Property Name() As String
Get
Dim Parts() As String
Dim s As String
If fRecordString = "" Then Return ""
Parts = Split(fRecordString, vbCrLf)
If Parts(C_TITLE) <> "" Then s = Parts(C_TITLE) + " "
If Parts(C_FORENAME) <> "" Then s = s + Parts(C_FORENAME) + " "
If Parts(C_SURNAME) <> "" Then s = s + Parts(C_SURNAME)
Return s
End Get
End Property
End Class
I then use this code elsewhere in my program,
Dim en As IEnumerator = Records.GetEnumerator
While en.MoveNext
' Add each name to the Name list
lstNames.Items.Add(New CustomerDetails(en.Current.ToString).Name)
End While
This works exactly as I want, I used the parameterised constructer to pass
a string to the class, which then uses the name property to return a
formatted string all in one neat line of code.
The question I am (finally) asking is, is this creating a memory leak as I
am creating new instances of the class with no obvious way of disposing
of them, or will this be taken care of by the garbage collector? Also,
would this be classed as bad programming style.
As you can probably tell I am new to VB.NET having come from
a VB6 background and I haven't yet quite got my head around the
new programming features.
Thanks for your time,
Regards,
Martin Horn.