我有这暴露了一个的ArrayList
以下公共财产:
I've got the following public property which exposes an Arraylist
:
public ArrayList SpillageRiskDescriptions
{
get
{
return _SpillageRiskDescriptions;
}
set
{
_SpillageRiskDescriptions = value;
}
}
在其他地方我打电话
Elsewhere I'm calling
SpillageRiskDescriptions.Add("VENTILATE AREA");
SpillageRiskDescriptions.Add("DO NOT ALLOW SPILLAGE TO ENTER MAINS");
这些似乎(通过属性)来将元素添加到私人的ArrayList _SpillageRiskDescriptions
而我会一直期待这会导致一个问题。所以我是正确的思想,属性返回一个引用以原始变量,而不是通过的价值传递给它?这是因为的ArrayList
是引用类型?将在同一个发生在一个 INT
(比如?)
These seem to be adding elements to the private ArrayList _SpillageRiskDescriptions
(through the property) whereas I would've expected this to cause a problem. Therefore am I correct in thinking that properties return a reference to the original variable and not passing it by value? Is this because ArrayList
is a reference type? Will the same happen with an int
(for example?)
推荐答案
从技术上讲,它总是由价值,但你要明白什么是被通过。因为它是一个引用类型,你传递一个参考回(但按价值计算)。
Technically it's always by value, but you have to understand what is being passed. Since it's a reference type, you are passing a reference back (but by value).
希望是有道理的。你总是通过的结果回值,但如果类型是引用您传递基准回值,这意味着你可以改变的对象,而不是哪个对象是指。
Hope that makes sense. You always pass the result back by value, but if the type is a reference you are passing the reference back by value, which means you can change the object, but not which object it refers to.
相关推荐
最新文章