本来只是想加点东西,结果调用后发生无限递归:
public void InvokeA() { Action A = () => { Console.WriteLine("Invoked A,list deep 1 "); }; A = () => { Console.WriteLine("Invoked A,list deep 2 "); A(); }; A(); }
那么解决方法如下:
public void InvokeA() { Action A2 = () => { Console.WriteLine("Invoked A,list deep 1 "); }; Action A3 = () => { Console.WriteLine("Invoked A,list deep 2 "); A2(); }; A = A3; A(); }
时间: 2024-10-11 16:53:27