问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication14{publicdelegatevoidcatjiaoEventHanler(objectsend,catjiaoeventArgse);classcat{publiceventcatjiaoEventHanlercatjiaoevent;publicvoidCatjiao(){Console.WriteLine("咪咪。。。。咪咪。。。咪咪咪咪。。。。咪咪咪咪");if(catjiao!=null){catjiao(this,newcatjiaoeventArgs());}}classmouse{publicstaticvoidTing(objectsend,catjiaoeventArgse){Console.WriteLine("mouse跑了");}}publicclasscatjiaoeventArgs:EventArgs{publicDateTimedt;publiccatjiaoeventArgs(){dt=DateTime.Now;}}classProgram{staticvoidMain(string[]args){cata=newcat();a.Catjiao+=newcatjiaoEventHanler(Catjiao);a.Catjiao();}}}}
解决方案
解决方案二:
报什么错?
解决方案三:
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceConsoleApplication14{classcat{publicdelegatevoidcatjiaoEventHanler(objectsend,cat.catjiaoeventArgse);publiceventcatjiaoEventHanlercatjiaoevent;publicvoidCatjiao(){Console.WriteLine("咪咪。。。。咪咪。。。咪咪咪咪。。。。咪咪咪咪");if(catjiaoevent!=null){catjiaoevent(this,newcatjiaoeventArgs());}}classmouse{publicstaticvoidTing(objectsend,catjiaoeventArgse){Console.WriteLine("mouse跑了");}}publicclasscatjiaoeventArgs:EventArgs{publicDateTimedt;publiccatjiaoeventArgs(){dt=DateTime.Now;}}classProgram{staticvoidMain(string[]args){cata=newcat();mousemu=newmouse();a.catjiaoevent+=newcatjiaoEventHanler(mouse.Ting);a.Catjiao();}}}}你的代码真乱,这样就不出错了但你想练习猫抓老鼠的代理可不是这样的