不要使用 ArrayList! [英] Don't use ArrayList!

查看:35
本文介绍了不要使用 ArrayList!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们经常告诉我不要使用 ArrayList 在 VB.NET 中创建数组.我想听听大家的意见,为什么不呢?创建和操作数组内容、维度等的最佳方法是什么?

People often tell me not to use ArrayList for making my arrays in VB.NET. I would like to hear opinions about that, why shouldn't I? What is the best method for creating and manipulating array contents, dimensions etc?

谢谢.

推荐答案

改用通用列表.ArrayList 不是类型化的,这意味着您可以拥有一个包含字符串、数字、+++ 的列表.相反,您应该使用这样的通用列表:

Use generic lists instead. ArrayList is not typed, meaning that you can have a list with strings, numbers, +++. Rather you should use a generic list like this:

Dim list1 As New List(Of String) ' This beeing a list of string

lists 类还允许您动态扩展列表,但是,它还强制执行键入,这有助于编写更清晰的代码(您不必进行类型转换)和不易出错的代码.

The lists-class also allows you to expand the list on the fly, however, it also enforces typing which helps write cleaner code (you don't have to typecast) and code that is less prone to bugs.

ArrayList 一般而言只是一个 List(Of Object).

ArrayList is gennerally speaking just a List(Of Object).

这篇关于不要使用 ArrayList!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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