看板 C_Sharp 關於我們 聯絡資訊
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 謝謝大家 --
Gamakatsu: 因為綠營很愛看電視 但我跟你講白的 北洪中秀南柱柱11/28 23:20
Gamakatsu: 現在這時間點帶風向真的沒用了 現實世界的風向早就變了11/28 23:31
Gamakatsu: 我真的很喜歡那句 退潮之後就知道誰沒穿褲子11/28 23:32
Gamakatsu: 選舉沒有確定的 但總統立委贏面大 總統又比立委更穩些11/28 23:33
Gamakatsu: 不用多久了 1/16以後就知道誰沒穿褲子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
fo40225: 多點傳送委派只會回傳最後一個方法的回傳值 11/02 21:47
bantime: return 似乎只會接到最後一個 總不可能如果回傳int 11/02 21:47
bantime: 結果最後回來變成int[]吧 11/02 21:47
fo40225: msdn.microsoft.com/zh-tw/library/system.delegate 11/02 21:48
fo40225: 備註倒數第二段 11/02 21:48
O187: 你應該用迴圈去接 11/02 22:47
testPtt: 做完一次先輸出一次 11/03 00:22