为什么 ArrayList 没有标记为 [Obsolete]? [英] Why isn't ArrayList marked [Obsolete]?

查看:30
本文介绍了为什么 ArrayList 没有标记为 [Obsolete]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过深思熟虑和研究 ArrayList,我个人真的很想说已经过时了,2.0以后我没有理由用这个类了.但是由于它没有被标记为 [Obsolete],有什么我不知道的用法比使用泛型类更好吗?如果是,请举例说明.谢谢.

After a deep thought and looking into the implementation of ArrayList, personally I really want to say It's obsolete, I have no reason to use this class after 2.0. But since it's not marked as [Obsolete], is there any usage that I didn't know, better than using a generic class? If yes, please give an example. Thanks.

EDITList为例,它提供了ArrayList的所有功能,并且是强类型的.那么我们什么时候需要使用ArrayList?也许有时它有更好的表现?我不知道.如果你能告诉我一些 ArrayList 的特别之处,我很感激.

EDIT Let's take List<T> as an example, it provides all functions of ArrayList, and it's strongly-typed. So when do we need to use ArrayList? Maybe sometimes it has a better performance? I don't know. I appreciate if you can show me something special of ArrayList.

推荐答案

我认为对于新代码来说,它应该被认为实际上已经过时了,但是没有令人信服的理由将其标记为过时并在 2.0 之前编写的所有代码中创建警告发布.

I think it should be considered effectively obsolete for new code, but there's no compelling reason to mark it obsolete and create warnings in all code which was written before 2.0 was released.

根据我的经验,大多数已被 Microsoft 标记为过时的类型和成员在某些方面是非常危险的,如果您仍有代码库使用它们,则应该真正修复它们.虽然使用 ArrayList 很痛苦,并且(至少在理论上)容易在执行时而不是编译时发现与类型相关的错误,但该类型的工作已经足够好......通常真的没有令人信服的理由更改现有代码.当我碰巧在使用 ArrayList 的代码区域工作时,我通常会考虑这种改变,而不是积极寻找它的每一个用法.

In my experience, most of the types and members which have been marked obsolete by Microsoft are actively dangerous in some respect, and should really be fixed if you still have a codebase using them. While using ArrayList is painful and (at least theoretically) prone to discovering type-related bugs at execution time rather than compile time, the type does its job well enough... often there's really no compelling reason to change existing code. It's the kind of change I'd generally consider when I already happened to be working on an area of code which was using ArrayList, rather than actively seeking out every usage of it.

这篇关于为什么 ArrayList 没有标记为 [Obsolete]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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