在vb.net中循环遍历泛型列表

在vb.net中循环遍历泛型列表,vb.net,Vb.net,在我的VB.net应用程序中,我正在填充我的customer对象并在其中循环,如下所示 由于有成千上万的客户,我想一次为500名客户提供服务 在vB.net中,是否还有一个For循环可以一次性处理500个客户 我没有使用LinQ,因为数据库是Oracle 有类似的吗 谢谢 Dim customerList as new List(of customer) Dim Customer as new Customer Try CustomerList=dataAccess.GetAllCustome

在我的VB.net应用程序中,我正在填充我的customer对象并在其中循环,如下所示

由于有成千上万的客户,我想一次为500名客户提供服务

在vB.net中,是否还有一个For循环可以一次性处理500个客户

我没有使用LinQ,因为数据库是Oracle

有类似的吗

谢谢

Dim customerList as new List(of customer)
Dim Customer as new Customer

Try
CustomerList=dataAccess.GetAllCustomers()

if not CustomerList is nothing then

   For each Customer in CustomerList
       BuildXML(custmer.Name,Customer.age,Customer.city)
   next
       ProcessXMLWS(strxml)
end if

Catch ex as exception
   LogError(ex.message)
End try

您可以在500个
Customer
对象块之间循环,如下所示:

For i As Integer = 0 To CustomerList.Count Step 500
    'Do things
Next
If CustomerList IsNot Nothing Then
然而,这对你没有任何好处。 您的代码正在单独使用每个
客户
对象,因此您一次只能使用500个对象

编辑

如果您的意思是只想处理前500个
Customer
对象,请尝试以下操作:

For i As Integer = 0 To Math.Min(500, CustomerList.Count)
    Set Customer = CustomerList(i)

    BuildXML(custmer.Name, Customer.age, Customer.city)
Next

另外,您不应该将
Dim Customer编写为新客户
——通过添加
New
关键字,您可以创建一个从未使用过的额外
Customer
实例。相反,编写
Dim Customer As Customer
来声明变量,而不创建新的
Customer
实例

此外,您还可以在If语句中使用VB的
IsNot
关键字,如下所示:

For i As Integer = 0 To CustomerList.Count Step 500
    'Do things
Next
If CustomerList IsNot Nothing Then
使用计数器变量

Dim counter as Integer = 1
For each Customer in CustomerList
   If counter = 500 Then
       ProcessXMLWS(strxml)
       strxml="" '//Empty if any.'
       counter = 1
   Next
   BuildXML(custmer.Name, Customer.age, Customer.city)   
   counter += 1
next

你的意思是像分页这样的事情吗?如果你所做的只是一次处理一行,那么分500行进行处理又有什么用呢?当然,在一个循环中完成所有行会更容易。谢谢adatapost。我不想在500后就离开。我想继续每500条记录