我们如何在vb.net中更改数组大小 [英] How we change array size in vb.net
本文介绍了我们如何在vb.net中更改数组大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我声明了Dim arr1(2) as string
我需要根据一些输入来更改数组大小.
例如.我想将数组大小从2更改为4,我需要使用哪种方法?
I declared Dim arr1(2) as string
I need to change array size based on some input.
Eg. I want to change array size from 2 to 4, what method would I need to use?
推荐答案
数组设计不佳,无法调整大小.相反,如果您需要任何大小可变的内容,请始终使用System.Collections.Generic.List<string>
(或任何其他元素类型);否则,请使用System.Collections.Generic.List<string>
(或其他任何元素类型).您可以使用其方法ToArray
返回数组.
—SA
Arrays are poorly designed for re-size. Instead, if you need anything with variable size, always useSystem.Collections.Generic.List<string>
(or any other element type); you can get back to array using its methodToArray
.
—SA
尝试 Array.Resize(arr1, 4)
.
Redim arr1(4) as string
'' if u r trieng to preserve previous data than
Redim preserve arr1(4) as string
这篇关于我们如何在vb.net中更改数组大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文