ArrayLists 有什么不好? [英] What's so bad about ArrayLists?

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

问题描述

我正在努力增强我公司的平台,在我的研究期间,我收到了很多人的评论,他们说应该避免使用 ArrayList.然而,他们从来没有给出太多解释,我也找不到任何关于他们为什么如此糟糕的文章.

I'm working on enhancing the platforms in my company and during my research, I've come across a lot of comments from people saying that ArrayLists should be avoided. However, they never gave much explanation why and I can't find any articles about why they're so awful.

推荐答案

Arraylists"(有时也称为vectors")是完美的数据结构;只是 ArrayList 是 C# 中应该避免的类.

"Arraylists" (also sometimes called "vectors") are perfectly fine data structures; it's just that ArrayList is a class that should be avoided in C#.

原因是它不是通用的,因此您可以在其中存储任何 object,从而破坏了类型安全性.
使用 List 代替.

The reason is that it isn't generic, so you can store any object inside it, breaking type-safety.
Use List<T> instead.

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

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