您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > 微软内部C#技术培训资料 (Overview of C#)
Module2:OverviewofC#OverviewStructureofaC#ProgramBasicInput/OutputOperationsRecommendedPracticesCompiling,Running,andDebuggingStructureofaC#ProgramHello,WorldTheClassTheMainMethodTheusingDirectiveandtheSystemNamespaceDemonstration:UsingVisualStudiotoCreateaC#ProgramHello,WorldusingSystem;classHello{publicstaticintMain(){Console.WriteLine(Hello,World);return0;}}TheClassAC#ApplicationIsaCollectionofClasses,Structures,andTypesAClassIsaSetofDataandMethodsSyntaxAC#ApplicationCanConsistofManyFilesAClassCannotSpanMultipleFilesclassname{...}TheMainMethodWhenWritingMain,YouShould:Useanuppercase“M,”asin“Main”DesignateoneMainastheentrypointtotheprogramDeclareMainaspublicstaticintMainMultipleClassesCanHaveaMainWhenMainFinishes,orReturns,theApplicationQuitsTheusingDirectiveandtheSystemNamespaceThe.NETFrameworkProvidesManyUtilityClassesOrganizedintonamespacesSystemIstheMostCommonlyUsedNamespaceRefertoClassesbyTheirNamespaceTheusingDirectiveSystem.Console.WriteLine(Hello,World);usingSystem;…Console.WriteLine(Hello,World);Demonstration:UsingVisualStudiotoCreateaC#ProgramBasicInput/OutputOperationsTheConsoleClassWriteandWriteLineMethodsReadandReadLineMethodsTheConsoleClassProvidesAccesstotheStandardInput,StandardOutput,andStandardErrorStreamsOnlyMeaningfulforConsoleApplicationsStandardinput–keyboardStandardoutput–screenStandarderror–screenAllStreamsMayBeRedirectedWriteandWriteLineMethodsConsole.WriteandConsole.WriteLineDisplayInformationontheConsoleScreenWriteLineoutputsalinefeed/carriagereturnBothMethodsAreOverloadedAFormatStringandParametersCanBeUsedTextformattingNumericformattingReadandReadLineMethodsConsole.ReadandConsole.ReadLineReadUserInputReadreadsthenextcharacterReadLinereadstheentireinputlineRecommendedPracticesCommentingApplicationsGeneratingXMLDocumentationDemonstration:GeneratingandViewingXMLDocumentationExceptionHandlingCommentingApplicationsCommentsAreImportantAwell-commentedapplicationpermitsadevelopertofullyunderstandthestructureoftheapplicationSingle-LineCommentsMultiple-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,andDebuggingInvokingtheCompilerRunningtheApplicationDemonstration:CompilingandRunningaC#ProgramDebuggingMultimedia:UsingtheVisualStudioDebuggerTheSDKToolsDemonstration:UsingILDASMInvokingtheCompilerCommonCompilerSwitchesCompilingfromtheCommandLineCompilingfromVisualStudioLocatingErrorsRunningtheApplicationRunningfromtheCommandLineTypethenameoftheapplicationRunningfromVisualStudioClickStartWithoutDebuggingontheDebugmenuDemonstration:CompilingandRunningaC#ProgramDebuggingExceptionsandJITDebuggingTheVisualStudioDebuggerSettingbreakpointsandwatchesSteppingthroughcodeExaminingandmodifyingvariablesMultimedia:UsingtheVisualStudioDebuggerTheSDKToolsGeneralToolsandUtilitiesWinFormsDesignToolsandUtilitiesSecurityToolsandUtilitiesConfigurationandDeploymentToolsandUtilitiesDemonstration:UsingIldasmLab2:CreatingaSimpleC#ProgramReviewStructureofaC#ProgramBasicInput/OutputOperationsRecommendedPracticesCompiling,Running,andDebugging
本文标题:微软内部C#技术培训资料 (Overview of C#)
链接地址:https://www.777doc.com/doc-3878675 .html