This is already 2, since Array / Collections (more precisely, any .NET class / reference type) are passed by default link.
In fact, the reference variable is passed by value, but behaves like passed by reference.
Why →
Consider var arr = new ArrayList();
The above statement first creates an ArrayList, and the reference is assigned to arr. (This is similar for any class, since the class is a reference).
Now during a call
example -> DummyMethod(arr) ,
the link is passed by value, that is, even if the parameter is assigned to another object inside the method, the original variable remains unchanged.
But since variable points (refer) to the same object, any operation performed on the main pointed object is reflected outside the called method.
In your example, any modification made for each will be reflected in the array.
If you want to avoid this behavior, you need to create a copy / clone of the object.
Example:
Instead
foreach (Foo x in dummyfoo) x.dummy++;
Use
foreach (Foo x in (ArrayList)dummyfoo.Clone()) x.dummy++;
Tilak source share