ArrayList.Add - 只添加引用? [英] ArrayList.Add - adds just references?

查看:20
本文介绍了ArrayList.Add - 只添加引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 MSDN 上找到,所以我在这里再次尝试:) 添加元素时,将其装箱并将对新对象的引用添加到集合中(如果它是值类型),或者如果元素是引用类型,只是将引用添加到arraylist.对吗?

I am unable to find on MSDN so I am trying here again :) When adding element, its boxed and the reference to new object is added to the collection (if it is value type) or if the element is reference type, just reference is added to arraylist. Is that correct?

所以它只包含 Object 类的实例,其中每个实例都引用堆上的值<

So it contains just instances of Object class where each one references the value on the heap<

推荐答案

这是正确的.

然而,在实际代码中,您应该使用通用的 Lists 而不是 ArrayLists.

In real code, however, you should use generic List<T>s instead of ArrayLists.

这篇关于ArrayList.Add - 只添加引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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