SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Microsoft Visual C# 2010
       Fourth Edition



           Chapter 1
  A First Program Using C#
Objectives
• Learn about programming
• Learn about procedural and object-oriented
  programming
• Learn about the features of object-oriented
  programming languages
• Learn about the C# programming language
• Write a C# program that produces output
• Learn how to select identifiers to use within your
  programs

Microsoft Visual C# 2010, Fourth Edition               2
Objectives (cont'd.)
• Improve programs by adding comments and using
  the System namespace
• Write and compile a C# program using the command
  prompt and using Visual Studio




Microsoft Visual C# 2010, Fourth Edition        3
Programming
• Computer program
     – Set of instructions that tells a computer what to do
     – Also called software
• Software comes in two broad categories
     – System software
     – Application software
• Machine language
     – Expressed as a series of 1s and 0s
           • 1s represent switches that are on, and 0s represent
             switches that are off

Microsoft Visual C# 2010, Fourth Edition                           4
Programming (cont'd.)
• High-level programming languages
     – Use reasonable terms such as “read,” “write,” or
       “add”
           • Instead of the sequence of on/off switches that
             perform these tasks
     – Allows you to assign reasonable names to areas of
       computer memory
     – Has its own syntax (rules of the language)
• Compiler
     – Translates high-level language statements into
       machine code
Microsoft Visual C# 2010, Fourth Edition                       5
Programming (cont'd.)
• Programming logic
     – Involves executing the various statements and
       procedures in the correct order
           • To produce the desired results
• Debugging
     – Process of removing all syntax and logical errors
       from the program




Microsoft Visual C# 2010, Fourth Edition                   6
Procedural and Object-Oriented
                 Programming
• Procedural program
     – Create and name computer memory locations that
       can hold values (variables)
     – Write a series of steps or operations to manipulate
       those values
• Identifier
     – A one-word name used to reference a variable
• Procedures or methods
     – Logical units that group individual operations used in
       a computer program
     – Called or invoked by other procedures or methods
Microsoft Visual C# 2010, Fourth Edition                     7
Procedural and Object-Oriented
             Programming (cont'd.)
• Object-oriented programming
     – An extension of procedural programming
• Objects
     – Similar to concrete objects in the real world
     – Contain their own variables and methods
     – Attributes of an object represent its characteristics
     – State of an object is the collective value of all its
       attributes at any point in time
     – Behaviors of an object are the things it “does”


Microsoft Visual C# 2010, Fourth Edition                       8
Procedural and Object-Oriented
             Programming (cont'd.)
• Originally used for two types of applications
     – Computer simulations
     – Graphical user interfaces (GUIs)




Microsoft Visual C# 2010, Fourth Edition
Features of Object-Oriented
              Programming Languages
• Classes
     – A category of objects or a type of object
     – Describes the attributes and methods of every object
       that is an instance, or example, of that class
• Objects
     – An instance of a class
• Encapsulation
     – Technique of packaging an object’s attributes and
       methods into a cohesive unit; undivided entity
     – Using a black box

Microsoft Visual C# 2010, Fourth Edition                   10
Features of Object-Oriented
      Programming Languages (cont'd.)
• Interface
     – Interaction between a method and an object
• Inheritance
     – Provides the ability to extend a class to create a
       more specific class
• Polymorphism
     – Describes the ability to create methods that act
       appropriately depending on the context



Microsoft Visual C# 2010, Fourth Edition                    11
The C# Programming Language
• Developed as an object-oriented and component-
  oriented language
• Part of Microsoft Visual Studio 2010
• Allows every piece of data to be treated as an
  object and to consistently employ the principles of
  object-oriented programming
• Contains a GUI interface that makes it similar to
  Visual Basic



Microsoft Visual C# 2010, Fourth Edition                12
The C# Programming Language
                  (cont'd.)

• Modeled after the C++ programming language
    – However, eliminates some of the most difficult
      features to understand in C++
• Very similar to Java
    – In C#, simple data types are objects




Microsoft Visual C# 2010, Fourth Edition               13
Writing a C# Program that Produces
                 Output
              class
                                                    literal string




                                                     argument
              namespace                    method




Microsoft Visual C# 2010, Fourth Edition                             14
Writing a C# Program that Produces
              Output (cont'd.)
• Namespace
     – Provides a way to group similar classes
• C# method parts
     – Method header
           • Includes the method name and information about what
             will pass into and be returned from a method
     – Method body
           • Contained within a pair of curly braces and includes all
             the instructions executed by the method



Microsoft Visual C# 2010, Fourth Edition                           15
Writing a C# Program that Produces
              Output (cont'd.)
• Whitespace
     – Any combination of spaces, tabs, and carriage
       returns (blank lines)
     – Organizes your code and makes it easier to read
• Access modifier
     – Defines the circumstances under which the method
       can be accessed
• Keywords
     – Predefined and reserved identifiers that have special
       meaning to the compiler

Microsoft Visual C# 2010, Fourth Edition                   16
Writing a C# Program that Produces
              Output (cont'd.)
• The name of the method is Main()
     – Every application must have a Main() method
     – Classes with a Main() method are called
       application classes; others are non-application
       classes
• The method returns nothing as indicated by the
  keyword void




Microsoft Visual C# 2010, Fourth Edition
Selecting Identifiers
• Requirements
     – Must begin with an underscore, at sign (@), or letter
           • Letters include foreign-alphabet letters
     – Can contain only letters, digits, underscores, and the
       at sign
           • Not special characters such as #, $, or &
     – Cannot be a C# reserved keyword




Microsoft Visual C# 2010, Fourth Edition                   18
Microsoft Visual C# 2010, Fourth Edition   19
Selecting Identifiers (cont'd.)




Microsoft Visual C# 2010, Fourth Edition       20
Selecting Identifiers (cont'd.)




Microsoft Visual C# 2010, Fourth Edition       21
Selecting Identifiers (cont'd.)




Microsoft Visual C# 2010, Fourth Edition       22
Improving Programs by Adding
               Program Comments
• Program comments
     – Nonexecuting statements that document a program
• Comment out
     – Turn a statement into a comment
• Types of comments in C#
     – Line comments
     – Block comments
     – XML-documentation format comments



Microsoft Visual C# 2010, Fourth Edition                 23
Adding Program Comments (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   24
Using the System Namespace




Microsoft Visual C# 2010, Fourth Edition   25
Using the System Namespace
                     (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   26
Writing and Compiling a C# Program
• Steps for viewing a program output
     – Compile source code into intermediate language
       (IL)
     – C# just in time (JIT) compiler translates the
       intermediate code into executable statements
• You can use either of two ways to compile
     – The command line
     – The Integrated Development Environment (IDE)




Microsoft Visual C# 2010, Fourth Edition                27
Compiling Code from the Command
                Prompt
• What to do if you receive an operating system error
  message
     – Command csc
           • Stands for “C Sharp compiler”




Microsoft Visual C# 2010, Fourth Edition            28
Compiling Code from the Command
            Prompt (cont'd.)
• What to do if you receive a programming language
  error message
     – Program error messages start with the program
       name
     – Followed by the line number and position within the
       line of the error




Microsoft Visual C# 2010, Fourth Edition
Compiling Code from within the Visual
             Studio IDE
• Advantages of using the Visual Studio IDE
     – Some of the code you need is already created for
       you
     – The code is displayed in color
     – You can double-click an error message and the
       cursor will move to the line of code that contains the
       error
     – Other debugging tools are available




Microsoft Visual C# 2010, Fourth Edition                    30
Compiling Code from within the Visual
         Studio IDE (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   31
You Do It
• Enter your first C# program into a text editor so you
  can execute it
• Use any text editor to write the following code and
  save it as Hello.cs




Microsoft Visual C# 2010, Fourth Edition              32
Compiling and Executing a Program
       from the Command Line
• Type the command that compiles your program:
         csc Hello.cs




Microsoft Visual C# 2010, Fourth Edition         33
Compiling and Executing a Program
    from the Command Line (cont'd.)
• Execute the program Hello.exe




Microsoft Visual C# 2010, Fourth Edition   34
Compiling and Executing a Program
      Using the Visual Studio IDE
• Steps
     –   Create a new project (console application)
     –   Enter the project name
     –   Write your program using the editor
     –   To compile the program, click Build on the menu
         bar, and then click Build Solution
           • As an alternative, you can press F6
     – Click Debug on the menu bar and then click Start
       Without Debugging


Microsoft Visual C# 2010, Fourth Edition                   35
Compiling and Executing a Program
   Using the Visual Studio IDE (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   36
Compiling and Executing a Program
   Using the Visual Studio IDE (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   37
Compiling and Executing a Program
   Using the Visual Studio IDE (cont'd.)




Microsoft Visual C# 2010, Fourth Edition   38
Deciding Which Method to Use
• Advantage of using the command line
     – Saves disk space
• Advantages of using the Visual Studio IDE
     – Automatic sentence completion
     – Words are displayed using different colors based on
       their category
     – Code automatically generated by the IDE is very
       helpful when writing a GUI



Microsoft Visual C# 2010, Fourth Edition                 39
Adding Comments to a Program
• Line comment example
         // Filename Hello.cs
         // Written by <your name>
         // Written on <today’s date>
• Block comment example
         /* This program demonstrates the use of
         the WriteLine() method to print the
         message Hello, world! */



Microsoft Visual C# 2010, Fourth Edition       40
Summary
• A computer program is a set of instructions that tell
  a computer what to do
• Understand differences between procedural
  programming and object-oriented programming
• Objects are instances of classes and are made up
  of attributes and methods
• The C# programming language is an object-
  oriented and component-oriented language
• System.Console.WriteLine() method
     – Produces a line of console output
Microsoft Visual C# 2010, Fourth Edition              41
Summary (cont'd.)
• You can define a C# class or variable by using any
  name or identifier
• Comments are nonexecuting statements that you
  add to document a program
     – Or to disable statements when you test a program
• Use namespaces to improve programs
• To create a C# program, you can use the Microsoft
  Visual Studio environment



Microsoft Visual C# 2010, Fourth Edition                  42

Weitere ähnliche Inhalte

Was ist angesagt?

9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02Terry Yoast
 
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Warren0989
 
Computer Programming
Computer ProgrammingComputer Programming
Computer ProgrammingBurhan Fakhar
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06Terry Yoast
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12Terry Yoast
 
Operators and Expressions in C#
Operators and Expressions in C#Operators and Expressions in C#
Operators and Expressions in C#Prasanna Kumar SM
 
9781439035665 ppt ch02
9781439035665 ppt ch029781439035665 ppt ch02
9781439035665 ppt ch02Terry Yoast
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Nicole Ryan
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#Prasanna Kumar SM
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
Visualizing UML’s Sequence and Class Diagrams Using Graph-Based Clusters
Visualizing UML’s Sequence and   Class Diagrams Using Graph-Based Clusters  Visualizing UML’s Sequence and   Class Diagrams Using Graph-Based Clusters
Visualizing UML’s Sequence and Class Diagrams Using Graph-Based Clusters Nakul Sharma
 
Mapping and visualization of source code a survey
Mapping and visualization of source code a surveyMapping and visualization of source code a survey
Mapping and visualization of source code a surveyNakul Sharma
 
9781439035665 ppt ch04
9781439035665 ppt ch049781439035665 ppt ch04
9781439035665 ppt ch04Terry Yoast
 

Was ist angesagt? (20)

Lecture 5
Lecture 5Lecture 5
Lecture 5
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02
 
Chapter 4 5
Chapter 4 5Chapter 4 5
Chapter 4 5
 
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chap02
Chap02Chap02
Chap02
 
JavaScript functions
JavaScript functionsJavaScript functions
JavaScript functions
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Chapter2
Chapter2Chapter2
Chapter2
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
Operators and Expressions in C#
Operators and Expressions in C#Operators and Expressions in C#
Operators and Expressions in C#
 
Intake 38_1
Intake 38_1Intake 38_1
Intake 38_1
 
9781439035665 ppt ch02
9781439035665 ppt ch029781439035665 ppt ch02
9781439035665 ppt ch02
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Visualizing UML’s Sequence and Class Diagrams Using Graph-Based Clusters
Visualizing UML’s Sequence and   Class Diagrams Using Graph-Based Clusters  Visualizing UML’s Sequence and   Class Diagrams Using Graph-Based Clusters
Visualizing UML’s Sequence and Class Diagrams Using Graph-Based Clusters
 
Mapping and visualization of source code a survey
Mapping and visualization of source code a surveyMapping and visualization of source code a survey
Mapping and visualization of source code a survey
 
9781439035665 ppt ch04
9781439035665 ppt ch049781439035665 ppt ch04
9781439035665 ppt ch04
 

Ähnlich wie Csc153 chapter 01

ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3Sisir Ghosh
 
LECTURE 1 - Introduction to Programming.pptx
LECTURE 1 - Introduction to Programming.pptxLECTURE 1 - Introduction to Programming.pptx
LECTURE 1 - Introduction to Programming.pptxAOmaAli
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programmingmaznabili
 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkAbdullahNadeem78
 
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
01. Introduction to Programming
01. Introduction to Programming01. Introduction to Programming
01. Introduction to ProgrammingIntro C# Book
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkDr.Neeraj Kumar Pandey
 
01. introduction to-programming
01. introduction to-programming01. introduction to-programming
01. introduction to-programmingStoian Kirov
 
Visual programming lab
Visual programming labVisual programming lab
Visual programming labSoumya Behera
 
First draft programming c++
First draft programming c++First draft programming c++
First draft programming c++藝輝 王
 
Advance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptxAdvance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptxpercivalfernandez3
 
Event Driven Programming in C#.docx
Event Driven Programming in C#.docxEvent Driven Programming in C#.docx
Event Driven Programming in C#.docxLenchoMamudeBaro
 

Ähnlich wie Csc153 chapter 01 (20)

C# Fundamental
C# FundamentalC# Fundamental
C# Fundamental
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 
LECTURE 1 - Introduction to Programming.pptx
LECTURE 1 - Introduction to Programming.pptxLECTURE 1 - Introduction to Programming.pptx
LECTURE 1 - Introduction to Programming.pptx
 
C#
C#C#
C#
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
 
Lecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net frameworkLecture-1&2.pdf Visual Programming C# .net framework
Lecture-1&2.pdf Visual Programming C# .net framework
 
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
 
01. Introduction to Programming
01. Introduction to Programming01. Introduction to Programming
01. Introduction to Programming
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net Framework
 
Intro1
Intro1Intro1
Intro1
 
01. introduction to-programming
01. introduction to-programming01. introduction to-programming
01. introduction to-programming
 
Introduction to Programming Lesson 01
Introduction to Programming Lesson 01Introduction to Programming Lesson 01
Introduction to Programming Lesson 01
 
Visual programming lab
Visual programming labVisual programming lab
Visual programming lab
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
First draft programming c++
First draft programming c++First draft programming c++
First draft programming c++
 
Advance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptxAdvance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptx
 
Event Driven Programming in C#.docx
Event Driven Programming in C#.docxEvent Driven Programming in C#.docx
Event Driven Programming in C#.docx
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 

Kürzlich hochgeladen

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

Csc153 chapter 01

  • 1. Microsoft Visual C# 2010 Fourth Edition Chapter 1 A First Program Using C#
  • 2. Objectives • Learn about programming • Learn about procedural and object-oriented programming • Learn about the features of object-oriented programming languages • Learn about the C# programming language • Write a C# program that produces output • Learn how to select identifiers to use within your programs Microsoft Visual C# 2010, Fourth Edition 2
  • 3. Objectives (cont'd.) • Improve programs by adding comments and using the System namespace • Write and compile a C# program using the command prompt and using Visual Studio Microsoft Visual C# 2010, Fourth Edition 3
  • 4. Programming • Computer program – Set of instructions that tells a computer what to do – Also called software • Software comes in two broad categories – System software – Application software • Machine language – Expressed as a series of 1s and 0s • 1s represent switches that are on, and 0s represent switches that are off Microsoft Visual C# 2010, Fourth Edition 4
  • 5. Programming (cont'd.) • High-level programming languages – Use reasonable terms such as “read,” “write,” or “add” • Instead of the sequence of on/off switches that perform these tasks – Allows you to assign reasonable names to areas of computer memory – Has its own syntax (rules of the language) • Compiler – Translates high-level language statements into machine code Microsoft Visual C# 2010, Fourth Edition 5
  • 6. Programming (cont'd.) • Programming logic – Involves executing the various statements and procedures in the correct order • To produce the desired results • Debugging – Process of removing all syntax and logical errors from the program Microsoft Visual C# 2010, Fourth Edition 6
  • 7. Procedural and Object-Oriented Programming • Procedural program – Create and name computer memory locations that can hold values (variables) – Write a series of steps or operations to manipulate those values • Identifier – A one-word name used to reference a variable • Procedures or methods – Logical units that group individual operations used in a computer program – Called or invoked by other procedures or methods Microsoft Visual C# 2010, Fourth Edition 7
  • 8. Procedural and Object-Oriented Programming (cont'd.) • Object-oriented programming – An extension of procedural programming • Objects – Similar to concrete objects in the real world – Contain their own variables and methods – Attributes of an object represent its characteristics – State of an object is the collective value of all its attributes at any point in time – Behaviors of an object are the things it “does” Microsoft Visual C# 2010, Fourth Edition 8
  • 9. Procedural and Object-Oriented Programming (cont'd.) • Originally used for two types of applications – Computer simulations – Graphical user interfaces (GUIs) Microsoft Visual C# 2010, Fourth Edition
  • 10. Features of Object-Oriented Programming Languages • Classes – A category of objects or a type of object – Describes the attributes and methods of every object that is an instance, or example, of that class • Objects – An instance of a class • Encapsulation – Technique of packaging an object’s attributes and methods into a cohesive unit; undivided entity – Using a black box Microsoft Visual C# 2010, Fourth Edition 10
  • 11. Features of Object-Oriented Programming Languages (cont'd.) • Interface – Interaction between a method and an object • Inheritance – Provides the ability to extend a class to create a more specific class • Polymorphism – Describes the ability to create methods that act appropriately depending on the context Microsoft Visual C# 2010, Fourth Edition 11
  • 12. The C# Programming Language • Developed as an object-oriented and component- oriented language • Part of Microsoft Visual Studio 2010 • Allows every piece of data to be treated as an object and to consistently employ the principles of object-oriented programming • Contains a GUI interface that makes it similar to Visual Basic Microsoft Visual C# 2010, Fourth Edition 12
  • 13. The C# Programming Language (cont'd.) • Modeled after the C++ programming language – However, eliminates some of the most difficult features to understand in C++ • Very similar to Java – In C#, simple data types are objects Microsoft Visual C# 2010, Fourth Edition 13
  • 14. Writing a C# Program that Produces Output class literal string argument namespace method Microsoft Visual C# 2010, Fourth Edition 14
  • 15. Writing a C# Program that Produces Output (cont'd.) • Namespace – Provides a way to group similar classes • C# method parts – Method header • Includes the method name and information about what will pass into and be returned from a method – Method body • Contained within a pair of curly braces and includes all the instructions executed by the method Microsoft Visual C# 2010, Fourth Edition 15
  • 16. Writing a C# Program that Produces Output (cont'd.) • Whitespace – Any combination of spaces, tabs, and carriage returns (blank lines) – Organizes your code and makes it easier to read • Access modifier – Defines the circumstances under which the method can be accessed • Keywords – Predefined and reserved identifiers that have special meaning to the compiler Microsoft Visual C# 2010, Fourth Edition 16
  • 17. Writing a C# Program that Produces Output (cont'd.) • The name of the method is Main() – Every application must have a Main() method – Classes with a Main() method are called application classes; others are non-application classes • The method returns nothing as indicated by the keyword void Microsoft Visual C# 2010, Fourth Edition
  • 18. Selecting Identifiers • Requirements – Must begin with an underscore, at sign (@), or letter • Letters include foreign-alphabet letters – Can contain only letters, digits, underscores, and the at sign • Not special characters such as #, $, or & – Cannot be a C# reserved keyword Microsoft Visual C# 2010, Fourth Edition 18
  • 19. Microsoft Visual C# 2010, Fourth Edition 19
  • 20. Selecting Identifiers (cont'd.) Microsoft Visual C# 2010, Fourth Edition 20
  • 21. Selecting Identifiers (cont'd.) Microsoft Visual C# 2010, Fourth Edition 21
  • 22. Selecting Identifiers (cont'd.) Microsoft Visual C# 2010, Fourth Edition 22
  • 23. Improving Programs by Adding Program Comments • Program comments – Nonexecuting statements that document a program • Comment out – Turn a statement into a comment • Types of comments in C# – Line comments – Block comments – XML-documentation format comments Microsoft Visual C# 2010, Fourth Edition 23
  • 24. Adding Program Comments (cont'd.) Microsoft Visual C# 2010, Fourth Edition 24
  • 25. Using the System Namespace Microsoft Visual C# 2010, Fourth Edition 25
  • 26. Using the System Namespace (cont'd.) Microsoft Visual C# 2010, Fourth Edition 26
  • 27. Writing and Compiling a C# Program • Steps for viewing a program output – Compile source code into intermediate language (IL) – C# just in time (JIT) compiler translates the intermediate code into executable statements • You can use either of two ways to compile – The command line – The Integrated Development Environment (IDE) Microsoft Visual C# 2010, Fourth Edition 27
  • 28. Compiling Code from the Command Prompt • What to do if you receive an operating system error message – Command csc • Stands for “C Sharp compiler” Microsoft Visual C# 2010, Fourth Edition 28
  • 29. Compiling Code from the Command Prompt (cont'd.) • What to do if you receive a programming language error message – Program error messages start with the program name – Followed by the line number and position within the line of the error Microsoft Visual C# 2010, Fourth Edition
  • 30. Compiling Code from within the Visual Studio IDE • Advantages of using the Visual Studio IDE – Some of the code you need is already created for you – The code is displayed in color – You can double-click an error message and the cursor will move to the line of code that contains the error – Other debugging tools are available Microsoft Visual C# 2010, Fourth Edition 30
  • 31. Compiling Code from within the Visual Studio IDE (cont'd.) Microsoft Visual C# 2010, Fourth Edition 31
  • 32. You Do It • Enter your first C# program into a text editor so you can execute it • Use any text editor to write the following code and save it as Hello.cs Microsoft Visual C# 2010, Fourth Edition 32
  • 33. Compiling and Executing a Program from the Command Line • Type the command that compiles your program: csc Hello.cs Microsoft Visual C# 2010, Fourth Edition 33
  • 34. Compiling and Executing a Program from the Command Line (cont'd.) • Execute the program Hello.exe Microsoft Visual C# 2010, Fourth Edition 34
  • 35. Compiling and Executing a Program Using the Visual Studio IDE • Steps – Create a new project (console application) – Enter the project name – Write your program using the editor – To compile the program, click Build on the menu bar, and then click Build Solution • As an alternative, you can press F6 – Click Debug on the menu bar and then click Start Without Debugging Microsoft Visual C# 2010, Fourth Edition 35
  • 36. Compiling and Executing a Program Using the Visual Studio IDE (cont'd.) Microsoft Visual C# 2010, Fourth Edition 36
  • 37. Compiling and Executing a Program Using the Visual Studio IDE (cont'd.) Microsoft Visual C# 2010, Fourth Edition 37
  • 38. Compiling and Executing a Program Using the Visual Studio IDE (cont'd.) Microsoft Visual C# 2010, Fourth Edition 38
  • 39. Deciding Which Method to Use • Advantage of using the command line – Saves disk space • Advantages of using the Visual Studio IDE – Automatic sentence completion – Words are displayed using different colors based on their category – Code automatically generated by the IDE is very helpful when writing a GUI Microsoft Visual C# 2010, Fourth Edition 39
  • 40. Adding Comments to a Program • Line comment example // Filename Hello.cs // Written by <your name> // Written on <today’s date> • Block comment example /* This program demonstrates the use of the WriteLine() method to print the message Hello, world! */ Microsoft Visual C# 2010, Fourth Edition 40
  • 41. Summary • A computer program is a set of instructions that tell a computer what to do • Understand differences between procedural programming and object-oriented programming • Objects are instances of classes and are made up of attributes and methods • The C# programming language is an object- oriented and component-oriented language • System.Console.WriteLine() method – Produces a line of console output Microsoft Visual C# 2010, Fourth Edition 41
  • 42. Summary (cont'd.) • You can define a C# class or variable by using any name or identifier • Comments are nonexecuting statements that you add to document a program – Or to disable statements when you test a program • Use namespaces to improve programs • To create a C# program, you can use the Microsoft Visual Studio environment Microsoft Visual C# 2010, Fourth Edition 42