有关数组和集合的问题 [英] questions about arrays and collections

查看:68
本文介绍了有关数组和集合的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H,


我从asp.net/vb.net开始,对阵列和

集合有一些疑问:


1)之间有什么区别:

dim x()为字符串



dim x as array


2)变量''x''在第二种情况下包含任何东西(字符串,整数

....在一起)?


3)正确的语法是什么?

dim x as arraylist



dim x作为arraylist()


4)在选择之间做什么:

dim x作为数组(或者如果没有差异则暗淡x())



dim x as arraylist


5)之间的选择:

dim x as arraylist



dim x作为列表(字符串)

感谢您的帮助。

Gilbert

H,

i''m starting with asp.net/vb.net and have some questions about arrays and
collections:

1) what''s the difference between:
dim x() as string
and
dim x as array

2) can variable ''x'' in the second case contain anything (string, integer
.... together)?

3) what is the correct syntax?
dim x as arraylist
or
dim x as arraylist()

4) what to choose between:
dim x as array (or if no difference dim x() )
and
dim x as arraylist

5) what to choose between:
dim x as arraylist
and
dim x as list(of string)
Thanks for helping me.
Gilbert

推荐答案

Gilbert写道:
Gilbert wrote:

H,


我开始了与asp.net/vb.net并对阵列有一些疑问和

集合:


1)之间的区别是什么:

dim x()as string



dim x as array
H,

i''m starting with asp.net/vb.net and have some questions about arrays and
collections:

1) what''s the difference between:
dim x() as string
and
dim x as array



差异是第一个是对字符串数组的引用,

而第二个是对任何类型数组的引用。

The difference is that the first one is a reference to a string array,
while the second one is a reference to any kind of array.


2)变量''x''在第二种情况下包含任何东西(字符串,整数

......在一起)?
2) can variable ''x'' in the second case contain anything (string, integer
... together)?



是,否。该引用可用于任何类型的数组。如果你给
分配一个字符串数组,你只能把字符串放在那个数组中。

如果另一方面你给它分配了一个Object数组,你可以放

数组中的任何内容。

Yes, and no. The reference can be used for any kind of array. If you
assign it an array of strings, you can only put strings in that array.
If you on the other hand assigns it an array of Object, you can put
anything in the array.


3)正确的语法是什么?

dim x as arraylist



dim x as arraylist()
3) what is the correct syntax?
dim x as arraylist
or
dim x as arraylist()



这取决于你想做什么。第一个向ArrayList声明一个引用

,第二个声明对一个

ArrayList对象数组的引用。

That depends on what you want to do. The first one declares a reference
to an ArrayList, the second one declares a reference to an array of
ArrayList objects.


4)之间的选择:

dim x as array(或者如果没有差异dim x())



dim x as arraylist
4) what to choose between:
dim x as array (or if no difference dim x() )
and
dim x as arraylist



再次,这取决于你想做什么。第一个声明对数组(任何类型)的

引用。第二个向ArrayList声明了一个引用



如果你想要一个动态增长的列表,那么ArrayList是好的。数组

无法调整大小。


如果您使用的是frameword 2.0,则可以使用generi列表而不是

ArrayList(除非您想在列表中混合数据类型)。泛型已经

使得ArrayList几乎已经过时了。

Again, that depends on what you want to do. The first one declares a
reference to an array (of any type). The second one declares a reference
to an ArrayList.

An ArrayList is good if you want a list that grows dynamically. An array
can not be resized.

If you are using frameword 2.0, you can use a generi list instead of an
ArrayList (unless you want to mix data types in the list). Generics has
made ArrayList almost obsolete.


5)之间的选择:

dim x as arraylist



dim x作为列表(字符串)
5) what to choose between:
dim x as arraylist
and
dim x as list(of string)



猜怎么着?这取决于你想做什么。 ;)


ArrayList相当于List(Of Object)。如果你想要一个可以混合数据类型的列表

,那就是你可以使用的。如果你只想要

将字符串放入列表中,你一定要选择第二个。

-

G?ran Andersson

_____
http://www.guffa.com


感谢您的解释。

如果您不介意,还有2个问题...

1)dim x as string()= dim x()as string =一个字符串数组?


2)dim x as array()=一个数组阵列?这与dim x(,)相同吗?


" G?ran Andersson" < gu *** @ guffa.comschreef在bericht

新闻:%2 **************** @ TK2MSFTNGP03.phx.gbl ...
Thanks for your explanation.
If you don''t mind, 2 more questions ...

1)dim x as string() = dim x() as string = an array of string ?

2) dim x as array() = an array of array? Is this the same as dim x( , )?

"G?ran Andersson" <gu***@guffa.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...

Gilbert写道:
Gilbert wrote:

> H,

我是从asp.net/vb.net开始,对阵列和
集合有一些疑问:

1)之间的区别是什么:
dim x()as string

dim x as array
>H,

i''m starting with asp.net/vb.net and have some questions about arrays and
collections:

1) what''s the difference between:
dim x() as string
and
dim x as array



区别在于第一个是对字符串数组的引用,

而第二个是对任何类型数组的引用。


The difference is that the first one is a reference to a string array,
while the second one is a reference to any kind of array.


> 2)在第二种情况下变量''x'可以包含任何内容(字符串) ,整数
......在一起)?
>2) can variable ''x'' in the second case contain anything (string, integer
... together)?



是,否。该引用可用于任何类型的数组。如果你给
分配一个字符串数组,你只能在该数组中放入字符串。如果

另一方面你给它分配了一个Object数组,你可以在数组中放入任何



Yes, and no. The reference can be used for any kind of array. If you
assign it an array of strings, you can only put strings in that array. If
you on the other hand assigns it an array of Object, you can put anything
in the array.


> 3)正确的语法是什么?
dim x as arraylist

dim x as arraylist()
>3) what is the correct syntax?
dim x as arraylist
or
dim x as arraylist()



这取决于你想做什么。第一个声明引用了一个ArrayList,而第二个声明了对ArrayList数组的引用

个对象。


That depends on what you want to do. The first one declares a reference to
an ArrayList, the second one declares a reference to an array of ArrayList
objects.


> 4)之间的选择:
dim x as array(或者如果没有差异dim x())

dim x as arraylist
>4) what to choose between:
dim x as array (or if no difference dim x() )
and
dim x as arraylist



再次,这取决于你想做什么。第一个声明对数组(任何类型)的

引用。第二个向ArrayList声明了一个引用



如果你想要一个动态增长的列表,那么ArrayList是好的。数组

无法调整大小。


如果您使用的是frameword 2.0,则可以使用generi列表而不是

ArrayList(除非您想在列表中混合数据类型)。泛型已经

使ArrayList几乎过时。


Again, that depends on what you want to do. The first one declares a
reference to an array (of any type). The second one declares a reference
to an ArrayList.

An ArrayList is good if you want a list that grows dynamically. An array
can not be resized.

If you are using frameword 2.0, you can use a generi list instead of an
ArrayList (unless you want to mix data types in the list). Generics has
made ArrayList almost obsolete.


> 5)之间的选择:
dim x as arraylist

dim x作为列表(字符串)
>5) what to choose between:
dim x as arraylist
and
dim x as list(of string)



猜怎么着?这取决于你想做什么。 ;)


ArrayList相当于List(Of Object)。如果你想要一个

的列表,你可以混合数据类型,那就是你可以使用的。如果你只想把

字符串放在列表中,你一定要选择第二个。


-

G ?跑安德森

_____
http://www.guffa。 com




1)dim x as string()= dim x()as string =一个字符串数组?
1)dim x as string() = dim x() as string = an array of string ?




Yes


2)dim x as array()= an数组的数组?这与dim x(,)相同吗?

2) dim x as array() = an array of array? Is this the same as dim x( , )?



dim a as object = x(0)(0)在第一种情况下给出第一个一个。

dim a as object = x(0)(0) gives in the first situation the first one.


这篇关于有关数组和集合的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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