For i As Int16 = 0 To cboCity.Items.Count - 2 ' Why -2 here and
For j As Int16 = cboCity.Items.Count - 1 To i + 1 Step -1 ' -1 with all the other here????
If cboCity.Items(i).ToString = cboCity.Items(j).ToString Then
cboCity.Items.RemoveAt(j)
End If
Next
Next
vbMarkO said:This worked perfect....
But if you dont mind... might I ask you a question or 2 about this code?
Visual Basic:For i As Int16 = 0 To cboCity.Items.Count - 2 ' Why -2 here and For j As Int16 = cboCity.Items.Count - 1 To i + 1 Step -1 ' -1 with all the other here???? If cboCity.Items(i).ToString = cboCity.Items(j).ToString Then cboCity.Items.RemoveAt(j) End If Next Next
You put the count on the first line to - 2
but on the 2nd line -1 To i + 1 Step -1
Why? and What is actuially going on there?
vbMarkO said:One more question if I might...
You started your FOr loop with
For i As int16 Why not For i As Integer ???
I ask because thats the first time I saw in16 instead of Integer...
Diesel said:Ick bein.
Ok..ok...it's bubble sort...cept...it's not sorting.
A faster way could be the following...
Create a new list.
Loop through the source list (just once).
Check to see if the new list contains the item your adding, if it does, don't add it.
And listen...If your throwing away fruit, I'll take the extras.
Cags said:I personally would have thought it easier and perhaps more efficient to test for a city before adding it to the list in the first place. What I mean by this is that when you are parsing through the xml loading in the names you check ComboBox.Items.Contains() before adding it.
If comboBox1.Items.Contains(myCity) = False Then
comboBox1.Items.Add(myCity)
End If
Code:ComboBox1.Items(i).ToString
Are you not using the Contains function? No need to loop through.
Anyway, the indexer syntax in C# uses [].