调整在运行时数组VB.NET [英] Resizing an array at runtime in VB.NET

查看:133
本文介绍了调整在运行时数组VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows在运行时窗体应用程序,我会调整我每次添加元素的数组。所以,首先我必须调整为尺寸+ 1 ,然后将成员添加到该索引。我该怎么做呢?


解决方案

您的可能的使用使用ReDim 语句,但这真的不是你最好的选择。如果你的阵列将被常变换大小的尤其的,因为它听起来像你只是追加,你应该使用一个通用的名单(共T)或类似的集合类型。

您可以使用它,就像你使用一个数组,增加,添加一个项目到底是为 MyList.Add(项目)

要使用一个通用的列表中,添加进口System.Collections.Generics 到文件的顶部。然后,你将宣布一个新的整数列表如下:

 昏暗MYLIST作为新的列表(整数)()

或字符串列表如下:

 昏暗MYLIST作为新的列表(字符串)()

您应该明白了吧。

In my Windows Forms application at runtime I will be resizing an array each time I add an element. So first I must resize to the size + 1, and then add a member to this index. How do I do this?

解决方案

You could use the ReDim statement, but this really isn't your best option. If your array will be changing sizes often, especially as it sounds like you're just appending, you should probably use a generic List(Of T) or similar collection type.

You can use it just like you use an array, with the addition that adding an item to the end is as easy as MyList.Add(item)

To use a generic list, add Imports System.Collections.Generics to the top of the file. Then, you would declare a new integer list like this:

Dim MyList As New List(Of Integer)()

or a string list like this:

Dim MyList As New List(Of String)()

You should get the idea.

这篇关于调整在运行时数组VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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