Hi, Am I correct in thinking the following snippet does not work (the array items are not modified) because the array is of integer which is value type.
class Program
{
public static void Main()
{
int[] ints = new int[] { 1,2 };
Array.ForEach(ints, new Action<int>(AddTen));
// ints is not modified
}
static void AddTen(int i)
{
i+=10;
}
}
The same would apply if the example used an array of string, presumably because string is immutable.
The question I have is:-
Is there a way around this? I can't change the signature of the callback method - for instance by adding the ref keyword and I don't want to wrap the value type with a class - which would work...
(Of course, I could simply write an old fashioned foreach loop to do this!)