加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 07:23:26 所属栏目:百科 来源:网络整理
导读:在我的VB.net应用程序中,我填充了我的客户对象并循环遍历它,如下所示. 由于有成千上万的客户,我想一次做500个客户. 无论如何我还可以再用一个For循环来在vB.net中一次性处理500个客户 我没有使用LinQ,因为数据库是Oracle. 有没有像 谢谢 Dim customerList as
在我的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读