ArrayList problem

danasegarane

Active member
Joined
Jun 14, 2006
Messages
41
Programming Experience
Beginner
Hi all,
I am using Array List to store values.I am using this code.
VB.NET:
Public Class Recovery
        Public nFilename As String
        Public nLockedby As String
        Public nActivityID As String
 
        Public Sub New(ByVal nfilename As String, ByVal nLockedby As String, ByVal nActivityid As String)
            MyBase.New()
            Me.nFilename = nfilename
            Me.nLockedby = nLockedby
            Me.nActivityID = nActivityid
        End Sub
 
    End Class
Public Shared Function GetPreviousStatus() As Boolean
 'Dim sTemparray As New ArrayList  'Initialized separtely
   If sTemparray.Contains(New Recovery(sFilename, sLockedby, sActivityid)) = False Then
           sTemparray.Add(New Recovery(sFilename, sLockedby, sActivityid))
    End If
End Function

Here I want to the Filename to be unique in the list.But this code allows the duplicate filename to be stored in the list.How can I restrict this

Dana
 
Your list doesn't contain "filename", it contains "Recovery"s. If you want to index the list by unique filename property of Recovery you should use a Dictionary(Of String, Recovery). You could also keep the List(Of Recovery) and make yourself a lookup function that checks all items and return Boolean True/False if an item has the unique filename or not.
 
Back
Top