是列表<对象>ArrayList 的良好替代品? [英] Is List&lt;Object&gt; a good replacement for ArrayList?

查看:25
本文介绍了是列表<对象>ArrayList 的良好替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ArrayList,我在旧的 Compact Framework 代码中使用,似乎在新的 (.NET 4.5.1) 代码中不可用.

ArrayList, which I use in legacy Compact Framework code, does not seem to be available in newfangled (.NET 4.5.1) code.

我正在其中存储自定义类的实例.

I am storing instances of custom classes in it.

有什么更好的替代品 - List,或者有什么更合适的?

What is a good replacement for it - List<Object>, or is there something more suitable?

推荐答案

正如@HighCore 在他的评论中提到的,你应该使用 List 的通用形式,List.如果您定义了多个需要包含在该列表中的类,它们可能具有共同的属性和方法.在这种情况下,您可以为该组类创建一个 abstract 类.

As @HighCore mentioned in his comment, you should use the generic form of List, List<T>. If you have several classes defined that you need to include in that List, they probably have common properties, methods. In that case, you can make an abstract class for the group of classes.

List 是一个可能的替代品,但不是一个好的替代品.

List<Object> is a possible replacement, but not a good one.

这篇关于是列表<对象>ArrayList 的良好替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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