Moose Pickard

Moose Pickard

  • NA
  • 64
  • 70.5k

Type name incremented with foreach?

Oct 12 2010 3:58 AM
Hi

I've got a simple question I think.
I've got a foreach loop:
            foreach (Car car in carrental.cars){
int i = 0; ListViewItem item1 = new ListViewItem(car.Name);
item1.SubItems.Add(car.Owner);
item1.SubItems.Add(car.Release);
item1.SubItems.Add(Convert.ToString(car.Mileage));
listView1.Items.AddRange(new ListViewItem[] {item1}); i++; }

You can see that this code inserts items to listview.
It does work, I just tested in writing the post.
But I'm just thinking how could I add the incremen int i to the name of the item.
Like this: item1, item2, item3.
I know I could do it with for loop.
Is it possible with foreach?

Answers (2)