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

查看:143
本文介绍了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?

编辑:所以它仅包含其中的每个引用堆&LT值对象类的实例;

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

推荐答案

这是正确的。

在实际code,但是,你应该使用一般的列表&LT; T&GT; 的S代替的ArrayList 秒。

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

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

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