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");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With