《C#考试题》代码阅读题.docx

上传人:b****4 文档编号:4385247 上传时间:2023-05-07 格式:DOCX 页数:24 大小:16.74KB
下载 相关 举报
《C#考试题》代码阅读题.docx_第1页
第1页 / 共24页
《C#考试题》代码阅读题.docx_第2页
第2页 / 共24页
《C#考试题》代码阅读题.docx_第3页
第3页 / 共24页
《C#考试题》代码阅读题.docx_第4页
第4页 / 共24页
《C#考试题》代码阅读题.docx_第5页
第5页 / 共24页
《C#考试题》代码阅读题.docx_第6页
第6页 / 共24页
《C#考试题》代码阅读题.docx_第7页
第7页 / 共24页
《C#考试题》代码阅读题.docx_第8页
第8页 / 共24页
《C#考试题》代码阅读题.docx_第9页
第9页 / 共24页
《C#考试题》代码阅读题.docx_第10页
第10页 / 共24页
《C#考试题》代码阅读题.docx_第11页
第11页 / 共24页
《C#考试题》代码阅读题.docx_第12页
第12页 / 共24页
《C#考试题》代码阅读题.docx_第13页
第13页 / 共24页
《C#考试题》代码阅读题.docx_第14页
第14页 / 共24页
《C#考试题》代码阅读题.docx_第15页
第15页 / 共24页
《C#考试题》代码阅读题.docx_第16页
第16页 / 共24页
《C#考试题》代码阅读题.docx_第17页
第17页 / 共24页
《C#考试题》代码阅读题.docx_第18页
第18页 / 共24页
《C#考试题》代码阅读题.docx_第19页
第19页 / 共24页
《C#考试题》代码阅读题.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

《C#考试题》代码阅读题.docx

《《C#考试题》代码阅读题.docx》由会员分享,可在线阅读,更多相关《《C#考试题》代码阅读题.docx(24页珍藏版)》请在冰点文库上搜索。

《C#考试题》代码阅读题.docx

《C#考试题》代码阅读题

《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");

}

}

publicclassD:

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=newE();

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(PointClassmyclass);

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(PointClassp)

{

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);

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;

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();

app.swap(refa,refb);

Console.WriteLine(“a={0}b={1}”,a,b);

}

}

2.usingSystem;

classTest{

staticvoidMain()

{

for(inti=0;i<10;i++)

{

Console.Write(i+“”);

if(i%2!

=0)

Console.WriteLine();

}

}

}

1.usingSystem;

classTest{

publicvoidF(strings)

{

for(inti=0;i

Console.Write(s[i]);

return;

}

publicstaticvoidMain()

{

stringstr=“syd168编写及收集整理”;

Testt=newTest();

t.F(str);}}

2.usingSystem;

classDemo{

inta;

publicA(intn)

{

a=n;

}

publicintM()

{

if(a>0)

returna--;

elsereturn0;

}

}

classTest{

staticvoidMain()

{

Demox=newDemo(9

);

intk=x.M();

while(k>0)

{

Console.Write(“{0}\t”,k*k);

j=x.M();

}

}

}

1.usingSystem;

classStringDe

{

publicvoidf(strings)

{

for(intj=0;j

Console.Write(s[j]);

return;

}

publicstaticvoidMain()

{

stringstr1=“ABCDEFGH”;

StringDeob=newStringDe();

ob.f(str1);

}

}

3.usingSystem;

classCounterDown{

intval;

publicCounterDown(intn)

{val=n;}

publicintcount()

{

if(val<6)

returnval++;

elsereturn0;

}

}

classNSDemo

{publicstaticvoidMain()

{

CounterDowncd1=newCounterDown

(2);

inti=cd1.count();

while(i>0)

{

Console.Write(i*3+“”);

i=cd1.count();

}

}

}

1.usingSystem;

classDemo2

{

staticvoidMain()

{

intk=1,m;

while(k<=10)

{

m=k*k;

Console.Write("{0}\t",m);

k++;

}

}

}

2.usingSystem;

classARRAY

{

publicstaticvoidMain()

{

intoddsum=0;

intevensum=0;

int[]arr={1,5,2,3,6,7,12,15};

foreach(intkinarr)

{

if(k%2==0)

evensum+=k;

else

oddsum+=k;

}

Console.WriteLine(“evensum={0}”,evensum);

Console.WriteLine(“oddsum={0}”,oddsum);

}

staticvoidMain()

{

ARRAYa=newARRAY();

a.Fun();

}}

1.

usingSystem;classexception{

staticvoidMain()

{

for(inti=0;i<2;i++)

{

Console.WriteLine("i="+i);

try{

switch(i)

{

case0:

intt=10/i;

break;

case1:

thrownewException("人为抛出异常");

break;

}

}

catch(DivideByZeroExceptione)

{

Console.WriteLine(e.Message);

}

catch(Exceptione)

{

Console.WriteLine(e.Message);

}

finally

{

Console.WriteLine("Leavingtry.");

}

}

}

}

2.usingSystem;

classA

{

intx;

publicA(inti)

{

x=n;

}

publicintF()

{

if(x>0)

returnx--;

elsereturn0;

}

}

classTest{

staticvoidMain()

{

Aa=newA(9);

intj=a.F();

while(j>0)

{

Console.Write(“{0}\t”,j*j);

j=a.F();

}

}

}

1.

usingSystem;

classTest{

staticvoidMain()

{

inti,j,k;

for(i=1;i<=4;i++)

{

for(j=1;j<=4-i;j++)

Console.Write("");

for(k=1;k<=2*i-1;k++)

Console.Write("*");

Console.WriteLine();

}

}

}

2.usingSystem;

classCounterDown{

intval;

publicCounterDown(intn)

{

val=n;

}

publicintcount()

{

if(val<9)

returnval++;

elsereturn0;

}

}

classNSDemo{

publicstaticvoidMain()

{

Counter.CounterDowncd1=newCounter.CounterDown

(2);

inti=cd1.count();

while(i>0)

{

Console.Write(i+“”);

i=cd1.count();

}

}

}

1.usingSystem;

classStringDe

{

publicvoidf(strings)

{

for(intj=0;j

Console.Write(s[j]);

return;

}

publicstaticvoidMain()

{

stringstr1=“中华人民共和国于一九四九年建立”;

StringDeob=newStringDe();

ob.f(str1);

}

}

2.usingSystem;

delegatevoidMyEventHandler();

classMyEvent{

publiceventMyEventHandleractivate;

publicvoidfire()

{

if(activate!

=null)

activate();

}

}

classX{

intid;

publicX(intx)

{

id=x/2;

}

publicvoidXhandler()

{

Console.WriteLine(id);

}

}

classEventDemo{

staticvoidMain()

{

MyEventevt=newMyEvent();

Xx1=newX(8);

Xx2=newX(16);

Xx3=newX(0);

evt.activate+=newMyEventHandler(x1.Xhandler);

evt.activate+=newMyEventHandler(x2.Xhandler);

evt.activate+=newMyEventHandler(x3.Xhandler);

evt.fire();

}

}

1.usingSystem;classexception{

staticvoidMain()

{

for(inti=0;i<2;i++)

{

Console.WriteLine("i="+i);

try{

switch(i)

{

case0:

intt=10/i;

break;

case1:

thrownewException("人为抛出异常");

break;

}

}

catch(DivideByZeroExceptione)

{

Console.WriteLine(e.Message);

}

catch(Exceptione)

{

Console.WriteLine(e.Message);

}

finally

{

Console.WriteLine("Leavingtry.");

}

}

}

}

2.usingSystem;

classA

{

intx;

publicA(inti)

{

x=n;

}

publicintF()

{

if(x>0)

returnx--;

elsereturn0;

}

}

classTest{

staticvoidMain()

{

Aa=newA(9);

intj=a.F();

while(j>0)

{

Console.Write(“{0}\t”,j*j);

j=a.F();

}

}

}

1.

usingSystem;

classStringDe

{

publicvoidf(strings)

{

for(intj=0;j

Console.Write(s[j]);

return;

}

publicstaticvoidMain()

{

stringstr1=“中华人民共和国于一九四九年建立”;

StringDeob=newStringDe();

ob.f(str1);

}

}

2.usingSystem;

delegatevoidMyEventHandler();

classMyEvent{

publiceventMyEventHandleractivate;

publicvoidfire()

{

if(activate!

=null)

activate();

}

}

classX{

intid;

publicX(intx)

{

id=x/2;

}

publicvoidXhandler()

{

Console.WriteLine(id);

}

}

classEventDemo{

staticvoidMain()

{

MyEventevt=newMyEvent();

Xx1=newX(8);

Xx2=newX(16);

Xx3=newX(0);

evt.activate+=newMyEventHandler(x1.Xhandler);

evt.activate+=newMyEventHandler(x2.Xhandler);

evt.activate+=newMyEventHandler(x3.Xhandler);

evt.fire();

}

}

1.

usingSystem;

classTest

{

staticvoidF()

{

x=1;

while(x<=20)

{

Console.Write(x);

if(x%5==0)

Console.WriteLine();

else

Console.Write(“\t”);

}

staticvoidMain()

{

F();

}

}

2.

usingSystem;

classSumw

{

staticvoidMain()

{

intx=0,y=0;

do

{

x=x+1;

if(x%2!

=0)

continue;

y=y+1;

}

while(x<=10);

Console.WriteLine(“y={0}”,y);

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 视频讲堂

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2