在vb.net中循环遍历通用列表

在我的VB.net应用程序中,我填充了我的客户对象并循环遍历它,如下所示.

由于有成千上万的客户,我想一次做500个客户.

无论如何我还可以再用一个For循环来在vB.net中一次性处理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

但是,它对你没有任何好处.
您的代码单独使用每个Customer对象,因此您一次只能执行500个操作.

编辑:

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

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

    BuildXML(custmer.Name,Customer.city)
Next

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

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

If CustomerList IsNot Nothing Then

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐