shaggs shaggs - 4 months ago 85
C# Question

C# equivalent of for statment

The following statement is and I need the c# equivalent

For i As Integer = 0 To Me.ListBox2.Items.Count - 1
Id = Me.ListBox2.Items(i).ToString

I have tried numerous things but no luck.

If I do

for (int x = listBox2.Items.Count - 1; x >= 0; x --)
id = listBox.Item(x).ToString()

But says Non-invocable member 'List.Box.Items' cannot be used like a method


You need to use square brackets for the indexer in C#:

 id = listBox.Items[x].ToString();