[問題] Delegate回傳質疑問?
class Program
{
public delegate string MyDelegate();
static void Main(string[] args)
{
MyDelegate myDelegate = MyMethod1;
myDelegate += MyMethod2;
Console.WriteLine(myDelegate());
Console.ReadKey();
}
public static string MyMethod1()
{
Console.WriteLine("Mythod1");
return "Done";
}
public static string MyMethod2()
{
Console.WriteLine("Mythod2");
return "Done";
}
}
===========================================================
以上是目前自己在練習Delegate觀念時打的程式碼
想請問各位大大這段程式碼的結果為何是印出
MyMethod1
MyMethod2
Done
而不是
MyMethod1
MyMethod2
Done
Done
謝謝大家
--
→
11/28 23:20,
11/28 23:20
→
11/28 23:31,
11/28 23:31
→
11/28 23:32,
11/28 23:32
→
11/28 23:33,
11/28 23:33
→
11/28 23:35,
11/28 23:35
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.127.251.189
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1446468817.A.D4D.html
※ 編輯: Gamakatsu (140.127.251.189), 11/02/2015 20:54:23
→
11/02 21:47, , 1F
11/02 21:47, 1F
→
11/02 21:47, , 2F
11/02 21:47, 2F
→
11/02 21:47, , 3F
11/02 21:47, 3F
→
11/02 21:48, , 4F
11/02 21:48, 4F
→
11/02 21:48, , 5F
11/02 21:48, 5F
→
11/02 22:47, , 6F
11/02 22:47, 6F
→
11/03 00:22, , 7F
11/03 00:22, 7F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章