如何在运行时创建和引用Arraylist [英] How to create and reference an Arraylist at run-time

查看:120
本文介绍了如何在运行时创建和引用Arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在运行时创建一些arraylists。

设计时创建的arraylists的数量是未知的。

第一个新的名字创建arraylist是

数组的第一个元素,NameArray(一个公开声明的数组,具有未知数字

元素在设计时)。

第二个新创建的arraylist的名字是

NameArray等的第二个元素


问题1:

怎么能我从NameArray中检索该名称并在运行时将其分配给新的

创建的arraylist?

(我甚至不知道如何在设计时执行此操作顺便说一句)


问题2:这些arraylists中的数据需要从代码和附加数据的其他部分(子等)中获取

将被添加到

这些arraylists。


在代码中存储数据列表的最佳方法是什么?

(也许它不是一个arraylist)


保持手指交叉,谢谢!

I need to create a number of arraylists at run time.
The number of arraylists to be created is unknown at design time.
The name of the first newly created arraylist is the first element of
an array, NameArray (a Publicly declared array with an unknown number
of elements at design time).
The name of the second newly created arraylist is the second element of
NameArray, etc

Problem 1:
How can I retrieve that name from NameArray and assign it to the newly
created arraylist at run-time?
(I don''t even know how to do this at design time, by the way)

Problem 2: the data in these arraylists needs to be accesible from
other parts (subs etc) of the code and additional data will be added to
those arraylists.

What is the best way to store lists of data accross the code?
(Maybe it is not an arraylist)

Keeping my fingers crossed, thanks!

推荐答案

这是针对Visual Basic 2005的

vbnewbie写道:
This is for Visual Basic 2005
vbnewbie wrote:

我需要在运行时创建一些arraylists。

要创建的arraylists的数量在设计时是未知的。

第一个新创建的arraylist的名字是

数组的第一个元素,NameArray(公开声明的数组,未知数字

元素在设计时)。

第二个新创建的arraylist的名字是

NameArray等的第二个元素


问题1:

如何从NameArray中检索该名称并在运行时将其分配给新的

创建的arraylist?

(顺便说一句,我甚至不知道如何在设计时这样做)


问题2:这些arraylists中的数据需要从

其他部分(su bs等)代码和附加数据将被添加到

那些arraylists。


存储代码中数据列表的最佳方法是什么?

(也许它不是一个arraylist)


保持手指交叉,谢谢!
I need to create a number of arraylists at run time.
The number of arraylists to be created is unknown at design time.
The name of the first newly created arraylist is the first element of
an array, NameArray (a Publicly declared array with an unknown number
of elements at design time).
The name of the second newly created arraylist is the second element of
NameArray, etc

Problem 1:
How can I retrieve that name from NameArray and assign it to the newly
created arraylist at run-time?
(I don''t even know how to do this at design time, by the way)

Problem 2: the data in these arraylists needs to be accesible from
other parts (subs etc) of the code and additional data will be added to
those arraylists.

What is the best way to store lists of data accross the code?
(Maybe it is not an arraylist)

Keeping my fingers crossed, thanks!


Hello vbnewbie,
Hello vbnewbie,

vbnewbie写道:
vbnewbie wrote:

>我需要在运行时创建一些arraylists。
要创建的arraylists的数量在设计时是未知的。
第一个新创建的arraylist的名称是数组的第一个元素,NameArray(一个公开声明的数组,在设计时具有未知数量的元素)。
第二个新创建的arraylist的名称是第二个元素
NameArray等等
>I need to create a number of arraylists at run time.
The number of arraylists to be created is unknown at design time.
The name of the first newly created arraylist is the first element of
an array, NameArray (a Publicly declared array with an unknown number
of elements at design time).
The name of the second newly created arraylist is the second element of
NameArray, etc



你可以像这样制作一组arraylists:

Dim al()As ArrayList


ReDim al(1)''这里你实际上定义了你需要多少个arraylists

'。


al(0)= New ArrayList''创建新的Arraylists。在你的程序中

al(1)= New ArrayList''你可以用循环来做。


al(0).Add(" Test" ;)''向ArrayLists添加一些值

al(1).Add(" Test1")

You could make an array of arraylists like this:
Dim al() As ArrayList

ReDim al(1) ''Here you would actually define how many arraylists
''you need.

al(0) = New ArrayList ''Create new Arraylists. In your program
al(1) = New ArrayList ''you might do that with a loop.

al(0).Add("Test") ''Add some values to the ArrayLists
al(1).Add("Test1")


>问题1:
如何从NameArray中检索该名称,并在运行时将其分配给新创建的arraylist?
(我不是顺便说一句,我甚至不知道如何在设计时这样做。
>Problem 1:
How can I retrieve that name from NameArray and assign it to the newly
created arraylist at run-time?
(I don''t even know how to do this at design time, by the way)



你可以例如定义ArrayList中的第一个条目总是

包含名称。

You could e.g. define that the first entry in the ArrayList always
contains the name.


>问题2:这些arraylists中的数据需要从代码的其他部分(子等)访问,并且其他数据将添加到这些arraylists中。
>Problem 2: the data in these arraylists needs to be accesible from
other parts (subs etc) of the code and additional data will be added to
those arraylists.


>在代码中存储数据列表的最佳方法是什么?
(也许它不是一个arraylist)
>What is the best way to store lists of data accross the code?
(Maybe it is not an arraylist)



在这种情况下,我会在模块中公开它们。


最诚挚的问候,


HKSHK

In this case I would make them public in a module.

Best Regards,

HKSHK




对不起,我我不确定如何在一个模块中公开它们因为它们在运行时不存在


是否有一种类型的模块我可以在公共场合写代码?


I''m sorry, I am not sure how to make them public in a module since they
don''t exist at run time.
Is there a type of module in which I could write public code?


这篇关于如何在运行时创建和引用Arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆