.net - 对于 vb.net 中的每个循环

标签 .net vb.net foreach for-loop

我如何在 vb.net 中使用 for 循环之类的

dim start as integer
Dim customers as New List(Of Customers)

Customers=dataAcess.GetCustomers()

For each start=500 in  Customers.count
  'Do something here'
Next

我想为每 500 个客户处理一些数据.. 请帮忙

最佳答案

首先,不要创建New客户列表,如果您只是要为下一行的引用分配一个不同的列表。这有点傻这样做:

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

然后,对于循环,您需要一个简单的“For”循环而不是一个 for each。不要忘记在列表结束之前停止:

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

如果您使用的是 Visual Studio 2008,您也可以这样编写:

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

关于.net - 对于 vb.net 中的每个循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1328948/

相关文章:

c# - 实现 IDataGridViewEditingCell 但也有编辑控件的自定义 DataGridView 列?

c# - .Net MySql 错误 "The given key was not present in the dictionary"

c# - 如何在 .Net Web Api 上记录每个方法的执行时间和参数

php - 从数组中删除重复的 strlen 项?

c# - 恢复数据库超时?

.net - MDI窗体 'creep'(MDI窗口位置变化)

java - Java 中的 ServicePointManager 等价物

.net - 在 .net 网站中生成文本文件的最佳方法是什么?

javascript - 为什么 foreach 没有按预期工作?

c# - 在 foreach 循环中手动增加一个枚举数