A First Program Using C#

Slides:



Advertisements
Similar presentations
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Advertisements

The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 1: Introduction
© by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Computers: Tools for an Information Age
Advanced Object-Oriented Programming Features
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 13: Object-Oriented Programming
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
Introduction to Programming and Visual Basic
Creating a Console Application with Visual Studio
Chapter 1 Introduction to Programming and C# Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Module 1: Introduction to C# Module 2: Variables and Data Types
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 1: Creating Java Programs
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
An Object-Oriented Approach to Programming Logic and Design
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Using Visual Basic 6.0 to Create Web-Based Database Applications
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 Chapter Nine Using GUI Objects and the Visual Studio IDE.
XP Tutorial 8 Adding Interactivity with ActionScript.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
1.
Creating a Java Application and Applet
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 1: Introduction to Computers and Programming.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
IS 350 Course Introduction. Slide 2 Objectives Identify the steps performed in the software development life cycle Describe selected tools used to design.
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2015
Social Media And Global Computing Introduction to Visual Studio
CIS16 Application Development Programming with Visual Basic
Presentation transcript:

A First Program Using C# Chapter One A First Program Using C#

Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming language Learn how to write a C# program that produces output Learn how to select identifiers to use within your programs

Objective Learn how to compile and execute a C# program from the command line Learn how to add comments to a C# program Learn how to compile and execute a program using Visual Studio IDE Learn how to eliminate the reference to Out by using the System namespace

Programming A computer program is a set of instructions that you write to tell a computer what to do Programmers do not use machine language when creating computer programs. Instead, programmers tend to use high-level programming languages Each high-level language has its own syntax and limited set of vocabulary that is translated into machine code by a compiler In addition to understanding syntax, a programmer must also understand programming logic

Object-Oriented Programming Variables are named computer memory locations used to hold values that may vary Operations are usually called or invoked to manipulate variables A procedural program defines the variable memory locations, then calls a series of procedures to input, manipulate, and output the value stored in those locations A single procedural program often contains hundreds of variables and thousands of procedure calls

Object-Oriented Programming Object-oriented programming is an extension of procedural programming, which in addition to variables and procedures contains: objects, classes, encapsulation, interfaces, polymorphism, and inheritance Objects are object-oriented components Attributes of an object represent its characteristics A class is a category of objects or a type of object An instance refers to an object based on a class

Object-Oriented Programming For example: An Automobile is a class whose objects have the following attributes: year, make, model, color, and current running status Your 1997 red Chevrolet is an instance of the class that is made up of all Automobiles Methods of classes are used to change attributes and discover values of attributes The Automobile class may have the following methods: getGas(), accelerate(), applyBreaks()

Object-Oriented Programming Methods and variables in object-oriented programming are encapsulated, that is, users are only required to understand the interface and not the internal workings of the class Polymorphism and Inheritance are two distinguishing features in the object-oriented programming approach Polymorphism describes the ability to create methods that act appropriately depending on the context Inheritance provides the ability to extend a class so as to create a more specific class

The C# Programming Language C# was developed as an object-oriented and component-oriented language It exists as part of the Visual Studio .NET package C# (like Java) is modeled after the C++ programming language Pointers are not used in C# C# does NOT require the use of object destructors, forward declarations, or #include files It has the ability to pass by reference Multiple inheritance is not allowed in C#

Writing a C# Program that Produces Output “This is my first C# program” is a literal string of characters The string appears in parenthesis because it is a parameter or an argument The WriteLine() method prints a line of output on the screen

Writing a C# Program that Produces Output Out is an object that represents the screen The Out object was created and endowed with the method WriteLine() Not all objects have the WriteLine() method

Writing a C# Program that Produces Output Console is a class Console defines the attributes of a collection of similar “Console” objects

Writing a C# Program that Produces Output System is a namespace, which is a scheme that provides a way to group similar classes Namespaces are used to organize classes

Writing a C# Program that Produces Output The difference between the above code and the previous code is the amount of whitespace Both versions of code share the same method header (including access modifiers and other keywords)

Selecting Identifiers Every method used in C# must be part of a class A C# class name or identifier must meet the basic following requirements: An identifier must begin with an underscore or a letter An identifier can contain only letters or digits, not special characters such as #,$, or & An identifier cannot be a C# reserved keyword

Selecting Identifiers The reserved public keyword is an access modifier that defines the circumstance under which a class can be accessed

Writing a C# Program that Produces Output Code written for a C# program using a text editor

Compiling and Executing a Program from the Command Line After creating source code, you must do the following before you can view the program output: Compile the source code into intermediate language (IL) Use the C# just in time (JIT) compiler to translate the intermediate code into executable statements

Compiling and Executing a Program from the Command Line Output of Hello Program

Adding Comments to a Program In large programs it becomes difficult to remember why certain steps were included and the role of certain variables and methods Program comments are nonexecuting statements that you add to document a program You can also comment out various statements in a program to debug and observe the effects of the program with the statement or statements commented out

Adding Comments to a Program There are three types of comments in C#: Line comments Block comments XML-documentation format

Compiling and Executing a Program Using the Visual Studio IDE C# programs can also be written using the Visual Studio IDE (instead of a text editor). This approach offers many advantages including: Some of the code you need is already created for you The code is displayed in color, so you can more easily identify parts of your program If error messages appear when you compile your program, you can double-click on an error message and the cursor will move to the line of code that contains the error Other debugging tools are available

Overview of the Visual Studio 2005 IDE Microsoft Visual C# Express Edition Only support Visual C# programming language Start page A list of links to resources in the IDE and on the internet Visual C# Express Headlines and MSDN This section provides links to information about programming in C# Note: MSDN stands for Microsoft Developer Network

Start Page in Visual C# 2005 Express Edition. Hidden window Start Page links Empty Solution Explorer (no projects open) New Project button Start Page tab Start Page in Visual C# 2005 Express Edition.

Displaying a Web page in Visual Studio. Requested Web page (URL in location bar drop-down menu) Selected tab requested Web page Displaying a Web page in Visual Studio.

Creating a Console Application with the New Project dialog. Project name Creating a Console Application with the New Project dialog.

IDE with an open console application. Editor window IDE with an open console application.

Renaming the program file in the Properties window. Solution Explorer Properties window File Name Property Click Program.cs to display its properties Type Welcome1.cs here to rename the file Renaming the program file in the Properties window.

Compiling and Executing a Program Using the Visual Studio IDE Output of the Hello program as run from the Visual Studio IDE

Compiling and Executing a Program Using the Visual Studio IDE List of Hello Program Files

Eliminating the Reference to Out by Using the System Namespace A program may contain an unlimited number of statements, as long as they are each terminated by a semicolon

Eliminating the Reference to Out by Using the System Namespace The Output of ThreeLines program

Eliminating the Reference to Out by Using the System Namespace When you need to repeatedly use a class from the same namespace, you can shorten statements by using the “using” keyword Output is identical as the previous version of ThreeLines

Eliminating the Reference to Out by Using the System Namespace An alias is an alternative name for a class An alias can be used to shorten a long class name (as in the above example)

Chapter Summary A computer program is a set of instructions that you write to tell a computer what to do Procedural Programming involves creating computer memory locations, called variables, and a set of operations, called procedures. In object-oriented programming, you envision program components as objects that are similar to concrete objects in the real world The C# language was developed as an object-oriented and component-oriented language

Chapter Summary To write a C# program that produces a line of console output, you must pass a literal string as a parameter to the System.Console.Out.WriteLine() method You can define a C# class or variable by using any name or identifier that begins with an underscore or a letter, that contains only letters or digits, and that is not a C# reserved keyword To create a C# program, you can use the Microsoft Visual Studio environment or any text editor

Chapter Summary After you write and save a program, you must compile the source code Program comments are nonexecuting statements that add to document a program or to disable statements As an alternative to using the command line, you can compile and write your program within the Visual Studio IDE When you need to repeatedly use a class from the same namespace, you can shorten the statements you type by using a clause that indicates a namespace where the class can be found