Functions and Methods

Functions and Methods

ID:37579377

大小:202.36 KB

页数:58页

时间:2019-05-25

Functions and Methods_第1页
Functions and Methods_第2页
Functions and Methods_第3页
Functions and Methods_第4页
Functions and Methods_第5页
资源描述:

《Functions and Methods》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、FunctionsandMethodsFunctionsandMethods函数和方法☺agentzh(章亦春)☺2006.10☆Consistentinterface,Simpleinterface,richinterface一致的接口,简单的接口,丰富的接口C#seemstohavehundredsofdifferentcollectionclasses,usedinconsistentlyinthe.NETlibraries.--NedBatchelderC#似乎拥有成百上千个不同的集合类,它们在.NET类库中的使用是如此的不一致。Perl6'sarray➥Simp

2、leinterfacewithrichfunctionalitiesPerl6数组:简单的接口,丰富的功能。#useitasanordinaryarray:@item='dog','cat','mouse','tiger';@item[0].say;#prints'dog'say~@item[1..-1];#prints'catmousetiger'@item[2]='human';@item.push('camel','moose');#appendelements@item=(@item,'camel','moose');#justthesame#useitasas

3、tack(FILO):@item.push('moose');push@item,'elk';#justanotherway$top=@item[-1];$top=@item.pop();$top=@item.pop;#ditto#useitasaqueue(FIFO):@item.unshift(256);unshift@item,128,'hello';$elem=@item.shift();$elem=@item.shift;$elem=shift@item;say"lengthofthequeue:",@elem.elems;Makesimplethingsea

4、syandhardthingspossible.--LarryWall让简单的事情很容易办到,让困难的事情有可能办到。Writingastringtoafileshouldbeasimpletask,however...向一个文件写入一个字符串本该是一件很简单的任务,可是……#TheJavaway:importjava.io.*;classWriteFile{publicstaticvoidmain(Stringargs[]){FileOutputStreamfoStream;PrintStreampStream;try{foStream=newFileOutputStr

5、eam("somefile.txt");pStream=newPrintStream(foStream);pStream.println("Thisiswrittentoafile");pStream.close();}catch(Exceptione){System.err.println("Errorwritingtofile"+e);}}}/*TheCway:*/#include#includeintmain(){FILE*fh;if((fh=fopen("somefile.txt","w")==NULL){fprintf(stder

6、r,"Can'topenfile:%s",strerror(errno));return1;}fprintf(fh,"Thisiswrittentoafile");fclose(fh);return0;}#ThePerl5way:openmy$fh,">somefile.txt"ordie"Can'topenfile:$!";print$fh"Thisiswrittentoafile"ordie"Can'tprinttofile:$!";close$fh;☆outputarguments<=>returnvalues输出参数<=>返回值/*passresultsviaret

7、urnvalues*/intadd(inta,intb){returna+b;}...if(add(1,2)==3){printf("ok");}printf("%d",add(5,6));/*passresultsviaoutputarguments*/voidadd(inta,intb,int&c){c=a+b;}...inttemp;add(1,2,temp);if(temp==3){printf("ok");}add(5,6,temp);printf("%d",temp);☆Multiplereturnvalues多重返回值#Th

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。