shaggs shaggs - 1 year ago 152
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

Answer Source

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

 id = listBox.Items[x].ToString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download