外文翻译 - C#_第1页
外文翻译 - C#_第2页
外文翻译 - C#_第3页
外文翻译 - C#_第4页
外文翻译 - C#_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0外文文献WhereC#FitsInInonesense,C#canbeseenasbeingthesamethingtoprogramminglanguagesas.NETistotheWindowsenvironment.JustasMicrosofthasbeenaddingmoreandmorefeaturestoWindowsandtheWindowsAPIoverthepastdecade,VisualBasicandC+haveundergoneexpansion.AlthoughVisualBasicandC+haveendedupashugelypowerfullanguagesasaresultofthis,bothlanguagesalsosufferfromproblemsduetothelegaciesofhowtheyhaveevolved.InthecaseofVisualBasic6andearler,themainstrengthofthelanguagewasthefactthatitwassimpletounderstandanddidntmakemanyprogrammingtaskseasy,largelyhidingthedetailsoftheWindowsAPIandtheCOMcomponentinfrastructurefromthedeveloper.ThedownsidetothiswasthatVisualBasicwasnevertrulyobject-oriented,sothatlargeapplicationsquicklybecomedisorganizedandhardtomaintain.Aswellasthis,becauseVisualBasicssyntaxwasinheritedfromearlyversionsofBASIC(which,inturn,wasdesignedtobeintuitivelysimpleforbeginningprogrammerstounderstand,ratherthantowritelargecommercialapplications),itdidntreallylenditselftowell-structuredorobject-orientedprograms.C+,ontheotherhand,hasitsrootsintheANSIC+languagedefinition.ItisntcompletelyANSIcompliantforthesimplereasonthatMicrosoftfirstwroteitsC+compilerbeforetheANSIdefinitionhadbecomeofficial,butitcomesclose.Unfortunately,thishasledtotwoproblems.First,ANSIC+hasitsrootsinadecade-oldstateoftechnology,andthisshowsupinalackofsupportformodernconcepts(suchasUnicodestringsandgeneratingXMLdocumentation),andinsomearchaicsyntaxstructuresdesignedforthecompilersofyesteryear(suchastheseparationofdeclarationfromdefinitionofmemberfunctions).Second,MicrosofthasbeensimultaneouslytryingtoevolveC+intoalanguagethatisdesignedforhigh-1performancetasksonWindows,andinordertoachievethattheyvebeenforcedtoaddahugenumberofMicrosoft-specifickeywordsaswellasvariouslibrariestothelanguage.TheresultisthatonWindows,thelanguagehasbecomeacompletemess.JustaskC+developershowmanydefinitionsforastringtheycanthinkof:char*,LPTSTR,string,CString(MFCversion),CString(WTLversion),wchar_t*,OLECHAR*,andsoon.Nowenter.NETacompletelynewenvironmentthatisgoingtoinvolvenewextensionstobothlanguages.MicrosofthasgottenaroundthisbyaddingyetmoreMicrosoft-specifickeywordstoC+,andbycompletelyrevampingVisualBasicintoVisualBasic.NET,alanguagethatretainssomeofthebasicVBsyntaxbutthatissodifferentindesignthatwecanconsiderittobe,forallpracticalpurposes,anewlanguage.ItsinthiscontextthatMicrosofthasdecidedtogivedevelopersanalternativealanguagedesignedspecificallyfor.NET,anddesignedwithacleanslate.VisualC#.NETistheresult.Officially,MicrosoftdescribesC#asa“simple,modern,object-oriented,andtype-safeprogramminglanguagederivedfromCandC+.”Mostindependentobserverswouldprobablychangethatto“derivedfromC,C+,andJava.”Suchdescriptionsaretechnicallyaccuratebutdolittletoconveythebeautyoreleganceofthelanguage.Syntactically,C#isverysimilartobothC+andJava,tosuchanextentthatmanykeywordsarethesame,andC#alsosharesthesameblockstructurewithbraces()tomarkblocksofcode,andsemicolonstoseparatestatements.ThefirstimpressionofapieceofC#codeisthatitlooksquitelikeC+orJavacode.Behindthatinitialsimilarity,however,C#isaloteasiertolearnthanC+,andofcomparabledifficultytoJava.Itsdesignismoreintunewithmoderndevelopertoolsthanbothofthoseotherlanguages,andithasbeendesignedtogiveus,simultaneously,theeaseofuseofVisualBasic,andthehighperformance,low-levelmemoryaccessofC+ifrequired.SomeofthefeaturesofC#are:Fullsupportforclassesandobject-orientedprogramming,includingbothinterfaceandimplementationinheritance,virtualfunctions,andoperatoroverloading.Aconsistentandwell-definedsetofbasictypes.Built-insupportforautomaticgenerationofXMLdocumentation.Automaticcleanupofdynamicallyallocatedmemory.2Thefacilitytomarkclassesormethodswithuser-definedattributes.Thiscanbeusefulfordocumentationandcanhavesomeeffectsoncompilation(forexample,markingmethodstobecompiledonlyindebugbuilds).Fullaccesstothe.NETbaseclasslibrary,aswellaseasyaccesstotheWindowsAPI(ifyoureallyneedit,whichwontbeallthatoften).Pointersanddirectmemoryaccessareavailableifrequired,butthelanguagehasbeendesigned.insuchawaythatyoucanworkwithouttheminalmostallcases.SupportforpropertiesandeventsinthestyleofVisualBasic.Justbychangingthecompileroptions,youcancompileeithertoanexecutableortoalibraryof.NETcomponentsthatcanbecalledupbyothercodeinthesamewayasActiveXcontrols(COMcomponents).C#canbeusedtowriteASP.NETdynamicWebpagesandXMLWebservices.Mostoftheabovestatements,itshouldbepointedout,doalsoapplytoVisualBasic.NETandManagedC+.ThefactthatC#isdesignedfromthestarttoworkwith.NET,however,meansthatitssupportforthefeaturesof.NETisbothmorecomplete,andofferedwithinthecontextofamoresuitablesyntaxthanforthoseotherlanguages.WhiletheC#languageitselfisverysimilartoJava,therearesomeimprovements:inparticular,Javaisnotdesignedtoworkwiththe.NETenvironment.Beforeweleavethesubject,weshouldpointoutacoupleoflimitationsofC#.Theoneareathelanguageisnotdesignedforistime-criticalorextremelyhighperformancecodethekindwhereyoureallyareworriedaboutwhetheralooptakes1,000or1,050machinecyclestorunthrough,andyouneedtocleanupyourresourcesthemillisecondtheyarenolongerneeded.C+islikelytocontinuetoreignsupremeamonglow-levellanguagesinthisarea.C#lackscertainkeyfacilitiesneededforextremelyhighperformanceapps,includingtheabilitytospecifyinlinefunctionsanddestructorsthatareguaranteedtorunatparticularpointsinthecode.However,theproportionsofapplicationsthatfallintothiscategoryareverylow.C#isasafe,stable,simple,elegant,fromCandC+derivedfromtheobject-orientedprogramminglanguage.ItinheritsCandC+powerwhileremovingthecomplexityofsomeoftheircharacteristics(forexample,nomacrosandtemplatesdoesnotallowmultiple3inheritance.)VBC#combinesthevisualizationandsimpleC+,highoperatingefficiency,theoperationalcapacityofitspowerful,elegantstyle,grammar,languagefeaturesinnovativeandconvenientsupportforcomponentorientedprogrammingbecome.NETdevelopmentlanguageofchoice.II.TheadvantagesandfeaturesofC#Microsoftc#languagedefinitionmainlyfromtheCandC+inherited,andlanguageofmanyoftheelementsarealsoreflectsthis.C#inthedesignerfromtheC+inheritanceoptionaloptionthantheJavatoawiderangesome(suchasstructs)Italsoincreaseditsnewfeatures(forexample,thedefinitionofthesourcecodeversion).butitwastooimmature,cannotsqueezeJava.C#alsoneedtoevolveintoadevelopertoacceptandadoptthelanguage.whileMicrosoftiscurrentlyItsthenewlanguagecreateamomentumisalsonoteworthy.noweveryonesreactionwas:ThisisJavasfightback.C#ismorelikeJavasome,thoughMicrosoftisonthisissueremainsilent.Thisistheexpectedthing,Ithink,becauseJavahasrecentlybeenverysuccessfuluseofJava,thecompanyreportedthattheirproductivitythanC+beimproved.TheenormousimpactofJavaandallithasbeenwidelyacceptedbytheworkofthelanguageandplatforminthenumberofprogrammersobviousthatthe(estimatedworldwidetotalof2.5millionprogrammersusingJava).writteninthislanguagebythenumberofapplicationsisamazingandhasinfiltratedeverylevelofcomputing,includingwirelesscomputingandmobilephones(suchastheJapaneseinventedJavaphones).C#togetthisfieldintheuserprivileges?Wemustwaitandwaitandsee,ashasbeenthecompanysCEOandChairmanofSSIKalpathiS.Sureshpointedouttoit,Ifoundallthesearegradual.IfC#doesnotexist,wecanalwaysreturntoJavaorCandC+.Thesearenotentirelynewtechnology;theirgreatersenseofthemarketisonlybigcompaniesmanufacturinggimmick.WemustgivethemtimetosettledownandseeifthesearenotreallyhaveanyeffectontheITindustry.C#featuresinheritedfromtheJavaClass:ClassinC#,andJavaisverysimilartothestate.ThisisreasonablebecauseexperiencetellsusthatJavamodelworkswell.Javakeywordimporthasbeenreplacedusing,itplayed4thesamerole.AclassstartedThestartingpointisthestaticmethodMain().ThefollowingshowsthebasicHelloWorldprogramintheformof:usingSystem;classHellostaticvoidMain()Console.WriteLine(Hello,world);Inthisexample,SystemincludesthenamepointstoabasicsetofC#utilityclassnamespace(namespace).ThisnamespaceincludestheConsoleclass,whichinthisexampleisusedtooutputastring.Classisabstractandnon-succession:aclassbyShenMingchengabstractcannotbeinstantiated;itcanonlybeusedasabaseclass.C#lockkeywordlikeJavakeywordfinal,itaffirmsthataclassisnotabstract,erface:asinJava,aninterfaceisasetofabstractsetofmethodsdefined.Whenaclassorimplementaninterfacestructure,itmustimplementtheinterfacedefinedintheAllmethods.Asingleclasscanimplementseveralinterfaces.maybelatertherewillbesomesubtledifferences,butthisfeatureseemsunchangedwithJava.Booleanoperators:Booleanconditionalexpressionistheresultofdatatypes,Booleandatatypethisisalanguageindependentdatatypes.fromBooleantypetoothertypesofnodirectconversionprocess.BooleanconstantstrueandfalsearekeywordsinC#.errorhandling:IfJavainit,bythrowingandcatchingexceptionsobjecttomanagetheerrorhandlingprocess.Memorymanagement:fromthebottom.NETframeworkautomaticmemorygarbagecollection.C#fromCandC+inheritedcharacteristicsCompile:compiletheprogramdirectlyintoastandardbinaryexecutableform.IfthefrontoftheHelloWorldprogramissavedasatextfileandnamedHello.cs,itwillbecompiledintoanexecutableprogramnamedHello.exe.Structure:aC#structandC+,thestructureissimilar,becauseitcancontaindatastateandmethods.However,unlikeC+,C#structandclassisdifferentanddoesnot5supportinheritance.However,withJavathesamethatastructurecaninterface.Pre-compiled:C#compilerdirectivestosupportpre-existingconditionalcompilation,warning,errorreportsandcompilelinecontrol.Theavailablepre-compiledinstructionsare:#Define#Undef#If#Elif#Else#Endif#W#Error#LineThereisno#includedirective.Youcannotthenassignthesymbol#definestatements,sothereisnoconceptofreplacingthesourcecode-thesesymbolscanonlybeusedin#ifand#elifdirectivesin.Inthe#linedirectiveThenumber(andoptionalname)canalsomodifythelinenumberand#error#warningoutputfilename.Operatoroverloading:Someoperatorscanbeoverloaded,whileotherscannot.Inparticular,thereisnoassignmentoperatorcanbeoverloaded.Canbeoverloadedunaryoperatoris:+-!+-TruefalseCanbeoverloadedbinaryoperatorsare:+-*/%&|=!=!=:C#独有的特点C#最引人入胜的地方是它和Java的不同,而不是相似的地方.这一节(和这个系列第二部分的大部分地方)讲述了C#实现的和Java不同的地方或者Java根本没有的特点.中间代码:微软在用户选择何时MSIL应该编译成机器码的时候是留了很大的余地.微软公司很小心的声称MSIL不是解释性的,而是被编译成了机器码.它也明白许多-如果不是大多数的话-程序员认为Java程序要不可避免的比C编写的任何东西都要慢.而这种实现方式决定了基于MSIL的程序(指的是用C#,VisualBasic,ManagedC+-C+的一个符合CLS的版本-等语言编写的程序)将在性能上超过解释性的Java代码.当然,这一点还需要得到事实证明,因为C#和其他生成MSIL的编译器还没有发布.但是JavaJIT编译器的普遍存在使得Java和C#在性能上相对相同.象C#是编译语言而Java是解释性的,之类的声明只是商业技巧.Java的中间代码和MSIL都是中间的汇编形式的语言,它们在运行时或其它的时候被编译成机器代码.命名空间中的申明:当你创建一个程序的时候,你在一个命名空间里创建了一个或多个类.同在这个命名空间里(在类的外面)你还有可能声明界面,枚举类型和结构体.必须使用using关键字来引用其他命名空间的内容.基本的数据类型:C#拥有比C,C+或者Java更广泛的数据类型.这些类型是bool,byte,ubyte,short,ushort,int,uint,long,ulong,float,double,和decimal.象Java一样,所有这些类型

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论