欢迎来到天天文库
浏览记录
ID:37904024
大小:57.50 KB
页数:15页
时间:2019-06-02
《《C#考试题》——代码阅读题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《C#应用开发》——代码阅读题1.阅读下面的程序,并写出执行的结果。(10分)usingSystem;interfaceInter1{voidF();}publicclassA:Inter1{publicvirtualvoidF(){Console.WriteLine("A.F");}}publicclassB:A{publicoverridevoidF(){Console.WriteLine("B.F");}}publicclassC:B,Inter1{newpublicvirtualvoidF(){Console.WriteLine("C.F");}}publiccl
2、assD:C,Inter1{publicoverridevoidF(){Console.WriteLine("D.F");}voidInter1.F(){Console.WriteLine("D.FwithInter1");}}publicclassE:D{publicoverridevoidF(){Console.WriteLine("E.F");}}publicclassApp{staticvoidM(Aa){Inter1i=(Inter1)a;i.F();}staticvoidMain(){Aa1=newE();Bb1=newE();Cc1=newE();Dd1=n
3、ewE();Ee1=newE();a1.F();b1.F();c1.F();d1.F();e1.F();Aa2=newA();Ab2=newB();Ac2=newC();Ad2=newD();Ae2=newE();M(a2);M(b2);M(c2);M(d2);M(e2);}}2.阅读以下程序,试分别描述程序执行至①,②,③处时,变量s1,s2,c1,c2,c3在堆栈和托管堆中的情况,并说明原因。(10分)usingSystem;publicdelegatevoidD1(PointStructmystruct);publicdelegatevoidD2(PointClas
4、smyclass);publicdelegatevoidD3(refPointStructmystruct);publicstructPointStruct{publicintx;publicinty;publicPointStruct(intx,inty){this.x=x;this.y=y;}}publicclassPointClass{publicintx;publicinty;publicPointClass(intx,inty){this.x=x;this.y=y;}}classmyclass{publicstaticvoidSetClass(PointClas
5、sp){if(p.x==0)p.x=100;if(p.x==100)p.y+=100;}publicstaticvoidSetStruct(PointStructp){if(p.x==0)p.x=100;if(p.x==100)p.y+=100;}publicstaticvoidSetStruct(refPointStructp){if(p.x==0)p.x=100;if(p.x==100)p.y+=100;}staticvoidMain(){PointStructs1=newPointStruct(0,0);PointClassc1=newPointClass(0,0)
6、;PointStructs2=s1;PointClassc2=c1;PointClassc3=newPointClass(100,100);//------------------------------------------①SetClass(c1);SetStruct(s1);SetStruct(refs2);//------------------------------------------②D1d1=newD1(SetStruct);D2d2=newD2(SetClass);D3d3=newD3(SetStruct);d1+=d1;d2+=d2;d3+=d3
7、;d1(s2);d2(c2);d2(c3);d3(refs1);//------------------------------------------③Console.WriteLine("theend");}}《C#应用开发》——写出运行结果1.usingSystem;classMyTest{publicvoidswap(refintx,refinty){inttemp=x;x=y;y=temp;}}classtest{staticvoidMain(){inta=6,b=8;MyTestapp=newMyTest();ap
此文档下载收益归作者所有