我可以调整阵列的大小吗? [英] Can I resize an array?

查看:107
本文介绍了我可以调整阵列的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我声明了这样一个数组:


string [] scriptArgs = new string [10];


我可以稍后在代码中调整数组大小吗?


谢谢,

Max

Hi,

I declared an array like this:

string[] scriptArgs = new string[10];

Can I resize the array later in the code?

Thank you,
Max

推荐答案

否。


请改用Systems.Collections.ArrayList。

然后读一本好的C#书。


-dm

No.

Use Systems.Collections.ArrayList instead.
Then read a good C# book.

-dm


虽然在某些情况下可能更喜欢ArrayList,但你不需要选择

只是因为你想轻松调整大小。数组也很容易调整大小。


使用C#2.0只需使用Array.Resize(用于一维数组)。


在2.0之前,使用此处描述的方法:
http://www.tangiblesoftwaresolutions...20Preserve.htm

-

David Anton
www.tangiblesoftwaresolutions.com

即时C#:VB到C#转换器

即时VB:C#到VB转换器

即时C ++:C#到C ++转换器& VB到C ++转换器

即时J#:VB到J#转换器


" Maxwell2006"写道:
Although ArrayList may be preferable in some cases, you don''t need to choose
it just because you want to resize easily. Arrays are also easily resized.

With C# 2.0 simply use Array.Resize (for one-dimensional arrays).

Prior to 2.0, use the method described here:
http://www.tangiblesoftwaresolutions...20Preserve.htm
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Maxwell2006" wrote:


我声明了这样一个数组:

string [] scriptArgs = new string [10];

我可以稍后在代码中调整数组大小吗?

谢谢你,
Hi,

I declared an array like this:

string[] scriptArgs = new string[10];

Can I resize the array later in the code?

Thank you,
Max



麦克斯韦,

请记住,

通常调整固定阵列的大小是一个cpu coslty的过程(我不是

确定c#2.0)。


它通常涉及制作一个新数组,然后将

旧数组中的所有数据复制到其中,尽管这是实际上会发生什么样的情况。


Arraylist对阵列的效果会更高,这些阵列会经常调整

操作。这就是它提供的原因。

-dm

Maxwell,
please keep in mind that
generaly resizing a fixed array is a process that is cpu coslty (Im not
to sure about c# 2.0).

It generaly involves making a new array then copy everything from the
old array into it, though this is greatly oversimplfing what actuly
happens.

An Arraylist is more effecient for arrays that will undergo resizing
operations on a regular basis. That is why it was provided.

-dm


这篇关于我可以调整阵列的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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