ArrayList的VS名单<>在C#中 [英] ArrayList vs List<> in C#

查看:126
本文介绍了ArrayList的VS名单<>在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是的ArrayList 列表℃之间的差异;在C#;&GT?

难道只有列表<> 有一个类型,而的ArrayList

Is it only that List<> has a type while ArrayList doesn't?

推荐答案

是,pretty得多。 列表&LT; T&GT; 是一个泛型类。它支持存储特定类型的值,而无需进行转换,或从对象(这将招致装箱/拆箱的开销时, T 的ArrayList 情况下)值类型。 的ArrayList 只需商店对象引用。作为一个泛型集合,它实现了通用的IEnumerable&LT; T&GT; 接口,可以在LINQ很容易地使用(无需任何铸造 OfType 调用)。

Yes, pretty much. List<T> is a generic class. It supports storing values of a specific type without casting to or from object (which would have incurred boxing/unboxing overhead when T is a value type in the ArrayList case). ArrayList simply stores object references. As a generic collection, it implements the generic IEnumerable<T> interface and can be used easily in LINQ (without requiring any Cast or OfType call).

的ArrayList 所属的天C#没有泛型。这是有利于的pcated德$ P $列表与LT; T&GT; 。你不应该的ArrayList 在新的code的目标使用.NET> = 2.0,除非你有一个使用它的一个旧的API接口。

ArrayList belongs to the days that C# didn't have generics. It's deprecated in favor of List<T>. You shouldn't use ArrayList in new code that targets .NET >= 2.0 unless you have to interface with an old API that uses it.

这篇关于ArrayList的VS名单&LT;&GT;在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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