Link to home
Start Free TrialLog in
Avatar of jindalee
jindalee

asked on

How do I delete an element from an array

I have 2 arrays, FileList1 and FileList2. As I compare the 2, I want to delete any entries in FileList1 that are also in FileList2.

I found an answer at https://www.experts-exchange.com/questions/23721653/Compare-arrays-of-different-sizes.html but I get the error "RemoveAt is not a member of System.Array"

It seems to have worked for a previous questioner so why not for me?

I am using Visual Studio Express 2008, (Visual Basic).
Dim FileList1(count1) As String ' Count1 is determined by some previous code
            Dim FileList2(count2) As String ' Count2 is determined by some previous code
 
            ' Code to populate the arrays
 
           If FileList1.Count > FileList2.Count Then
                For i As Integer = FileList1.Count - 1 To 0 Step -1
                    For x As Integer = FileList2.Count - 1 To 0 Step -1
                        If FileList2(x).ToString = FileList1(i).ToString Then
                            FileList1.RemoveAt(i)
                            Exit For 
                        End If
                    Next
                Next
            End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia 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 srikanthreddyn143
srikanthreddyn143

As Webtubbs said, Array is not resizable. You have to use arraylist to add or remove items dynamically.
the asker in the pointer actually says that he has 2 arraylists.
Avatar of jindalee

ASKER

OOPS. So it does :S
Mr.jindalee,

the link you provided has used arraylist.I think you are using arrays.Right?
Haven't forgotten the question - I've been diverted to a higher priority task and haven't had the chance to try the suggestions. Will get back to it soon.
As soon as I changed from Array to ArrayList I was able to twek the code to do what I needed.

Thank you