I just started using VB.net for about an hour now and i encountered a problem with regards to using for each loop. Can anyone tell me why i got an error message saying that
"List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change."
Here is my code
Can anyone tell me why i got the error message? thanks
"List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change."
Here is my code
VB.NET:
If (ListBox1.Items.Count <> 0) Then
For Each fern As String In ListBox1.Items
If (fern = TextBox1.Text) Then
MessageBox.Show("The value the you are going to add is already in the list", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
ListBox1.Items.Add(TextBox1.Text)
End If
Next 'This is where the error shows up
Else
ListBox1.Items.Add(TextBox1.Text)
End If
Can anyone tell me why i got the error message? thanks