The code is very simple, not much to explain, if there are questions and suggestions please leave a message, back to the first time reply
C # code First
classProgram {Static voidMain (string[] args) {Mycallback MC=NewMycallback (); Mc. Callback (NewAction (Success),NewAction (failed)); Mc. Callback (NewAction (() ={Console.WriteLine ("non-parametric anonymous success"); }), NewAction (() ={Console.WriteLine ("non-parametric anonymous failed"); })); Mc. Callback (Newaction<Object> (Success),Newaction<Object>(failed)); Console.readkey (); //From Http://www.cnblogs.com/ahjesus respect the author's hard work results, reproduced please indicate the source, thank you! } Static voidsuccess () {Console.WriteLine ("No reference Success"); } Static voidfailed () {Console.WriteLine ("No reference failed"); } Static voidSuccessObjectstr) {Console.WriteLine (string) str); } Static voidFailedObjectstr) {Console.WriteLine (int) str); } } classMycallback { Public voidCallback (Action success, action failed) {success (); Failed (); //From Http://www.cnblogs.com/ahjesus respect the author's hard work results, reproduced please indicate the source, thank you! } Public voidCallback (action<Object> Success, action<Object>failed) {Success ("123"); Failed (456); } }
JS Code
<script type= "Text/javascript" >varMC =NewMycallback (); Mc. Callback (success, failed); Console.log (222); functionSuccess (str) {console.log (str); } functionfailed (num) {console.log (num); } MC. Callback (function(str) {console.log (str); }, function(num) {console.log (num); From Http://www.cnblogs.com/ahjesus respect the author's hard work results, reproduced please indicate the source, thank you! }) Console.log (333); functionMycallback () { This. Callback =function(Success, failed) {//no reference, no referenceSuccessdelegate =success; //From Http://www.cnblogs.com/ahjesus respect the author's hard work results, reproduced please indicate the source, thank you! FailedDelegate=failed; SetTimeout (' Successdelegate ("111") ', 1000);//AsynchronousSetTimeout (' FailedDelegate ("444") ', 4000);//Asynchronous //success ("123");//Sync //failed (456);//Sync } } </script>
Callback Callback C # and JS synchronous, asynchronous implementation