在VB.NET中如何实现通用列表的遍历操作?

2026-04-29 07:232阅读0评论SEO教程
  • 内容介绍
  • 相关推荐

本文共计385个文字,预计阅读时间需要2分钟。

在VB.NET中如何实现通用列表的遍历操作?

在我VB.net应用程序中,我填充了我的客户对象并遍历它,如下所示。由于有成千上万的客户,我想一次性处理500个客户。无论怎样,我还能再用一个For循环在VB.net中一次性处理500个客户吗?

在我的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.age, Customer.city) Next

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

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

在VB.NET中如何实现通用列表的遍历操作?

If CustomerList IsNot Nothing Then

本文共计385个文字,预计阅读时间需要2分钟。

在VB.NET中如何实现通用列表的遍历操作?

在我VB.net应用程序中,我填充了我的客户对象并遍历它,如下所示。由于有成千上万的客户,我想一次性处理500个客户。无论怎样,我还能再用一个For循环在VB.net中一次性处理500个客户吗?

在我的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.age, Customer.city) Next

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

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

在VB.NET中如何实现通用列表的遍历操作?

If CustomerList IsNot Nothing Then