我想打電話給Method2
,然後Method1
。我知道有這樣做有多種方式Method1(Method2());
但我只是嘗試了下面的代碼。 在下面的場景中Method2
沒有被調用。所以我只是想知道這個場景在哪裏有用,爲什麼C#提供了這種機制。如何在C#中調用一個接一個的方法?
public delegate void Action();
public static void Method1(Action action)
{
}
static void Main()
{
Method1(Method2);
return;
}
public static void Method2()
{
}
方法二不叫,因爲你沒有在方法一 – ASh
調用'action'順便說一句,你不需額外需要自己爲'委託Action',它自帶.NET 3.5 – HimBromBeere