For each loop in vb.net

Try the following

For Each current In customers
  '' // Do something here 
  Console.WriteLine(current.Name)
Next

Something like this:-

Dim customers as New List(Of Customer)

Customers=dataAcess.GetCustomers()

For Each customer AS Customer in  Customers
   '' // do something with the customer object
Next

Edit

Sounds like you want to select 500 of N items or perhaps the next 500. You could use the LINQ extension methods .Take and/or .Skip to achieve this. Use ToList then to create your list. E.g.:-

Dim customers as List(Of Customer)
customers = dataAccess.GetCustomers().Skip(500).Take(500).ToList()

If all you want to do enum through the customers then you could dispense with ToList().


First of all, don't create a New list of customers if you're just going to assign a different list to the reference on the next line. That's kinda dumb. Do it like this:

Dim customers As List(Of Customer) = dataAccess.GetCustomers()

Then, for the loop you need a plain "For" loop rather than a for each. Don't forget to stop before the end of the list:

For i As Integer = 500 To Customers.Count -1 
    'do something with Customers(i) here
Next i

If you're using Visual Studio 2008 you could also write it like this:

For each item As Customer in  Customers.Skip(500)
   'Do something with "item" here
Next

'This will start at 500 and process to the end....

for start as integer = 500 to Customers.Count

'process customer....
customer = Customers(start)

Next

To iterate the entire list:

for each cust as Customer in Customers

Next 

One note.... VB is case insensitive and your sample code seems to use lower case and upper case customers