清单< T> - 做我传递对象或引用? [英] List<T> - do I pass objects or references?

查看:93
本文介绍了清单< T> - 做我传递对象或引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经调查泛型和有以下问题:

Well I have looked into generics and have following question:

List<someClass> list=new List<someClass>

SomeClass MyInstance=SomeClass();

list.Add(MyInstance);



我不知道什么将被添加到列表 - 引用或引用类型的对象(指向实际MYINSTANCE值)结果
编辑:?或者我会添加值(即引用数据类型),它指向实际的对象。

I am not sure what will be added to list - reference or object of reference type (pointing to actual value of MyInstance).
Or I will add value (that is reference data type) which points to actual object?

感谢

推荐答案

当你处理你总是处理引用引用类型,所以引用将被添加到列表(副本实际上参考)。你实际上并没有一个选择;这就是语言是如何工作的。

When you deal with reference types you are always dealing with references, so a reference will be added to the list (a copy of the reference actually). You don't actually have a choice; that's how the language works.

这篇关于清单&LT; T&GT; - 做我传递对象或引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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