shaggs shaggs - 28 days ago 25
C# Question

C# equivalent of for statment

The following statement is vb.net 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

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

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