c# delegate that references and adds to itself

Viewed 89

When I run this code:

string x = "";
Action<int> myAction = (i) => x += ("A" + i);
myAction = (i) =>
{
    if (i > 0)
    {
        x += ("B" + i);
        myAction += (i2) => x += ("C" + i + i2);
        myAction(i - 1);
    }
};
myAction(3);
Console.WriteLine(x);

What prints is: B3B2B1C30C20C10C31C21C32

Can anyone give me an explanation as to why this gets printed?

1 Answers
Related