yeni kitap ch01

37
An Introduction To Object Oriented Programming Chapter 1 A First Program Using C#

Upload: irfan-memon

Post on 18-Dec-2015

237 views

Category:

Documents


1 download

DESCRIPTION

CH01

TRANSCRIPT

  • An Introduction To Object Oriented ProgrammingChapter 1A First Program Using C#

  • Microsoft Visual C# 2008, Third Edition*ProgrammingComputer programSet of instructions that tells a computer what to doMachine languageExpressed as a series of 1s and 0sHigh-level programming languagesUse reasonable terms such as read, write, or add

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Programming (continued)High-level programming language (continued)Has its own syntax (rules of the language)CompilerTranslates high-level language statements into machine codeProgramming logicInvolves executing the various statements and procedures in the correct order To produce the desired results

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Programming (continued)DebuggingProcess of removing all syntax and logical errors from the program

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Object-Oriented ProgrammingProcedural programCreate and name computer memory locations that can hold values (variables)Write a series of steps or operations to manipulate those valuesIdentifierA one-word name used to reference a variableProcedures or methodsLogical units that group individual operations used in a computer program

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Object-Oriented Programming (continued)Object-oriented programmingAn extension of procedural programmingNew features include:ObjectsSimilar to objects in the real worldContain their own variables and methodsAttributes of an object represent its characteristics

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Object-Oriented Programming (continued)New features include (continued):ClassA category of objects or a type of objectDescribes the attributes and methods of every object that is an instance, or example, of that classEncapsulationTechnique of packaging an objects attributes and methods into a cohesive unitInterfaceInteraction between a method and an object

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Object-Oriented Programming (continued)New features include (continued):PolymorphismDescribes the ability to create methods that act appropriately depending on the contextInheritanceProvides the ability to extend a class to create a more specific class

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*The C# Programming LanguageC# programming languageDeveloped as an object-oriented and component-oriented languageAllows every piece of data to be treated as an object and to employ the principles of object-oriented programmingContains a GUI interface

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*The C# Programming Language (continued)C# programming language (continued)Modeled after the C++ programming languageHowever, eliminates some of the most difficult features to understand in C++Very similar to JavaIn C# simple data types are objects

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Writing a C# Program that Produces Outputliteral stringargumentsmethodobjectclassnamespace

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Writing a C# Program that Produces Output (continued)NamespaceProvides a way to group similar classesC# method partsMethod Includes the method name and information about what will pass into and be returned from a method

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Writing a C# Program that Produces Output (continued)WhitespaceAny combination of spaces, tabs, and carriage returns (blank lines)Organizes your code and makes it easier to readKeywordsPredefined and reserved identifiers that have special meaning to the compilerAccess modifierDefines the circumstances under which the method can be accessed

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Selecting IdentifiersRequirementsMust begin with an underscore, at sign (@), or letterLetters include foreign-alphabet lettersCan contain only letters or digitsNot special characters such as #, $, or &Cannot be a C# reserved keyword

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Selecting Identifiers (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Selecting Identifiers (VALID)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Selecting Identifiers (Valid but UNCONVENTIONAL)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Selecting Identifiers (INVALID)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Adding Comments to a ProgramProgram commentsNonexecuting statements that document a programComment outTurn a statement into a commentTypes of comments in C#Line commentsBlock comments

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Adding Comments to a Program (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Eliminating the Reference to Out by Using the System Namespace

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Eliminating the Reference to Out by Using the System Namespace (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Writing and Compiling a C# ProgramSteps for viewing a program outputCompile source code into intermediate language (IL)C# just in time (JIT) compiler translates the intermediate code into executable statements

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling Code from the Command PromptCommand cscStands for C Sharp compiler

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling Code from within the Visual Studio IDEAdvantages of using the Visual Studio IDESome of the code you need is already created for youThe code is displayed in colorYou can double-click an error message and the cursor will move to the line of code that contains the errorOther debugging tools are available

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling Code from within the Visual Studio IDE (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Alternate Ways to Write a Main() MethodMain() method with parameters

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Alternate Ways to Write a Main() Method (continued)Main() method with a return type

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Entering a Program into an EditorUse any text editor to write the following code and save it as Hello.cs

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program from the Command LineType the command that compiles your program:csc Hello.cs

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program from the Command Line (continued)Execute the program Hello.exe

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program Using the Visual Studio IDEStepsCreate a new project (console application)Enter the project nameWrite your program using the editorTo compile the program, click Build on the menu bar, and then click Build SolutionAs an alternative, you can press F6Click Debug on the menu bar and then click Start Without Debugging

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program Using the Visual Studio IDE (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program Using the Visual Studio IDE (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program Using the Visual Studio IDE (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Compiling and Executing a Program Using the Visual Studio IDE (continued)

    Microsoft Visual C# 2008, Third Edition

  • Microsoft Visual C# 2008, Third Edition*Adding Comments to a ProgramLine comment example// Filename Hello.cs// Written by // Written on Block comment example/* This program demonstrates the use ofthe WriteLine() method to print themessage Hello, world! */

    Microsoft Visual C# 2008, Third Edition

    *************************************