Hi All, I am attempting to compare values in two arraylists to make sure all
the values are the same. I am running into trouble with my code if both
arraylists compare okay up until a point and I am looping using the length of
the primary arraylist. For example:
oApproved (3 elements here):
[0]Red
[1]Green
[2]Yellow
oFound (5 elements here):
[0]Red
[1]Green
[2]Yellow
[3]Orange
[4]Blue
If using my loop below, the comparison will exit before it sees the last two
elements of arraylist 2 should not be there and should be removed.
for (indexI = 0; indexI <= oApproved.Count - 1; )
{
if (oFound[indexJ].ToString() ==
oApproved[indexI].ToString())
{
//TODO: remove debug
//RaiseVerificationEvent("Debug++File found: " +
oFound[indexJ].ToString());
//System.Diagnostics.Debug.WriteLine("File Approved:
" + oFound[indexJ].ToString());
indexI += 1;
indexJ += 1;
RaiseVerificationEvent(indexI.ToString() + " ------
" + indexJ.ToString());
}
else
{
CFileIO.DeleteFile(oFound[indexJ].ToString());
RaiseVerificationEvent("Unapproved file: " +
oFound[indexJ].ToString() + " deleted.");
//TODO: remove debug
System.Diagnostics.Debug.WriteLine("File Unapproved:
" + oFound[indexJ].ToString());
indexJ += 1;
}
}
I can see the flaw in my logic is the "for (indexI = 0; indexI <=
oApproved.Count - 1; )" because it will stop comparing when it reaches the
length of the primary ArrayList (in this case oApproved). Is there a better
way to compare arraylists? Or maybe a proven looping structure for comparing
arrays?
Thank You.