微软内部C#技术培训资料 (Overview of C#)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Module2:OverviewofC#OverviewStructureofaC#ProgramBasicInput/OutputOperationsRecommendedPracticesCompiling,Running,andDebuggingStructureofaC#ProgramHello,WorldTheClassTheMainMethodTheusingDirectiveandtheSystemNamespaceDemonstration:UsingVisualStudiotoCreateaC#ProgramHello,WorldusingSystem;classHello{publicstaticintMain(){Console.WriteLine(Hello,World);return0;}}TheClassAC#ApplicationIsaCollectionofClasses,Structures,andTypesAClassIsaSetofDataandMethodsSyntaxAC#ApplicationCanConsistofManyFilesAClassCannotSpanMultipleFilesclassname{...}TheMainMethodWhenWritingMain,YouShould:Useanuppercase“M,”asin“Main”DesignateoneMainastheentrypointtotheprogramDeclareMainaspublicstaticintMainMultipleClassesCanHaveaMainWhenMainFinishes,orReturns,theApplicationQuitsTheusingDirectiveandtheSystemNamespaceThe.NETFrameworkProvidesManyUtilityClassesOrganizedintonamespacesSystemIstheMostCommonlyUsedNamespaceRefertoClassesbyTheirNamespaceTheusingDirectiveSystem.Console.WriteLine(Hello,World);usingSystem;…Console.WriteLine(Hello,World);Demonstration:UsingVisualStudiotoCreateaC#ProgramBasicInput/OutputOperationsTheConsoleClassWriteandWriteLineMethodsReadandReadLineMethodsTheConsoleClassProvidesAccesstotheStandardInput,StandardOutput,andStandardErrorStreamsOnlyMeaningfulforConsoleApplicationsStandardinput–keyboardStandardoutput–screenStandarderror–screenAllStreamsMayBeRedirectedWriteandWriteLineMethodsConsole.WriteandConsole.WriteLineDisplayInformationontheConsoleScreenWriteLineoutputsalinefeed/carriagereturnBothMethodsAreOverloadedAFormatStringandParametersCanBeUsedTextformattingNumericformattingReadandReadLineMethodsConsole.ReadandConsole.ReadLineReadUserInputReadreadsthenextcharacterReadLinereadstheentireinputlineRecommendedPracticesCommentingApplicationsGeneratingXMLDocumentationDemonstration:GeneratingandViewingXMLDocumentationExceptionHandlingCommentingApplicationsCommentsAreImportantAwell-commentedapplicationpermitsadevelopertofullyunderstandthestructureoftheapplicationSingle-LineCommentsMultiple-LineComments/*Findthehigherrootofthequadraticequation*/x=(-b+Math.Sqrt(b*b–4*a*c))/(2*a);//Gettheuser’snameConsole.WriteLine(Whatisyourname?);name=Console.ReadLine();GeneratingXMLDocumentation///summaryTheHelloclassprintsagreeting///onthescreen////summaryclassHello{///remarksWeuseconsole-basedI/O.///FormoreinformationaboutWriteLine,see///seealsocref=System.Console.WriteLine/////remarkspublicstaticvoidMain(){Console.WriteLine(Hello,World);}}Demonstration:GeneratingandViewingXMLDocumentationExceptionHandlingusingSystem;publicclassHello{publicstaticintMain(string[]args){try{Console.WriteLine(args[0]);}catch(Exceptione){Console.WriteLine(Exceptionat{0},e.StackTrace);}return0;}}Compiling,Running,andDebuggingInvokingtheCompilerRunningtheApplicationDemonstration:CompilingandRunningaC#ProgramDebuggingMultimedia:UsingtheVisualStudioDebuggerTheSDKToolsDemonstration:UsingILDASMInvokingtheCompilerCommonCompilerSwitchesCompilingfromtheCommandLineCompilingfromVisualStudioLocatingErrorsRunningtheApplicationRunningfromtheCommandLineTypethenameoftheapplicationRunningfromVisualStudioClickStartWithoutDebuggingontheDebugmenuDemonstration:CompilingandRunningaC#ProgramDebuggingExceptionsandJITDebuggingTheVisualStudioDebuggerSettingbreakpointsandwatchesSteppingthroughcodeExaminingandmodifyingvariablesMultimedia:UsingtheVisualStudioDebuggerTheSDKToolsGeneralToolsandUtilitiesWinFormsDesignToolsandUtilitiesSecurityToolsandUtilitiesConfigurationandDeploymentToolsandUtilitiesDemonstration:UsingIldasmLab2:CreatingaSimpleC#ProgramReviewStructureofaC#ProgramBasicInput/OutputOperationsRecommendedPracticesCompiling,Running,andDebugging

1 / 27
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功