int a = 10;
int b = 20;
int[] rihanna = // .... ?
for(int a=0; a<rihanna.length;a++)
rihanna[a]++;
Console.WriteLine("{0} {1} ",a,b) // what I want to see here is 11 and 21
void Increase(ref int x)
{
x++;
}
void Set(ref int x, int amount)
{
x = amount;
}
void Sample()
{
int a = 10;
int b = 20;
// Array of "increase variable" delegates
var increaseElements = new Action[] {
() => Increase(ref a),
() => Increase(ref b)
};
increaseElements[0](); // call delegate, unfortunately () instead of ++
Console.WriteLine(a); // writes 11
// And now with array of "set the variable" delegates:
var setElements = new Action<int>[] {
v => Set(ref a,v),
v => Set(ref b,v)
};
setElements[0](3);
Console.WriteLine(a); // writes 3
}