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

问题描述

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

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"(有时也称为向量")是非常好的数据结构.只是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<T>.

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

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

10-28 02:32