Chapter 1: A First Program Using C#

Similar documents
EEE-425 Programming Languages (2013) 1

Fundamentals of Programming Session 4

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

IT 374 C# and Applications/ IT695 C# Data Structures

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

CIS 3260 Intro. to Programming with C#

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Microsoft Visual Basic 2005: Reloaded

Lab # 2. For today s lab:

ENGR/CS 101 CS Session Lecture 3

Fundamental C# Programming

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Preview from Notesale.co.uk Page 3 of 36

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Chapter 2: Programming Concepts

Basic Keywords Practice Session

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Computer Science AP 2017 Summer Assignment Mrs. McFarland

CS313T ADVANCED PROGRAMMING LANGUAGE

Chapter 2: Basic Elements of C++

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2, Part I Introduction to C Programming

EL2310 Scientific Programming

Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia

Using the Dev C++ Compiler to Create a Program

Lab # 02. Basic Elements of C++ _ Part1

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CSc Introduction to Computing

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

c122mar413.notebook March 06, 2013

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Introduction To C#.NET

Objectives. In this chapter, you will:

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Creating a C++ Program

CS 177 Recitation. Week 1 Intro to Java

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

INFORMATICS LABORATORY WORK #2

Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

2. Functions I: Passing by Value

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Variables. Data Types.

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Basic Syntax - First Program 1

Software and Programming 1

Program Organization and Comments

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

CSE 230 Intermediate Programming in C and C++ Functions

PROGRAMMING FUNDAMENTALS

Chapter 1 INTRODUCTION

Visual C# Instructor s Manual Table of Contents

Fundamentals of Programming. By Budditha Hettige

Shut the Box. By the time you are done with this activity, you and your team should be able to:

Lecture 2 Tao Wang 1

Computer Science II Lecture 1 Introduction and Background

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Java Bytecode (binary file)

Introduction to Java

Introduce C# as Object Oriented programming language. Explain, tokens,

A A B U n i v e r s i t y

Full file at

Pace University. Fundamental Concepts of CS121 1

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Methods. Contents Anatomy of a Method How to design a Method Static methods Additional Reading. Anatomy of a Method

Programming for Engineers Introduction to C

CSI33 Data Structures

Exercise 1.1 Hello world

Lecture 02, Fall 2018 Friday September 7

WRITING CONSOLE APPLICATIONS IN C

COMP 202 Java in one week

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Introduction to Programming Using Java (98-388)

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Your First C++ Program. September 1, 2010

Probably the best way to start learning a programming language is with a program. So here is our first program:

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Simple Java Reference

Getting Started. C# Programming Getting Started 1

6.096 Introduction to C++ January (IAP) 2009

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

Course Outline. Introduction to java

Module 2: Introduction to a Managed Execution Environment

Introduction to C# Applications

Programming with C++ as a Second Language

Transcription:

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 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 2

Programming (cont d.) Part of the HelloWorld Program in machine language 3

Programming (cont d.) High-level programming language Uses 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 language 4

Programming (cont d.) Programming logic Involves executing the various statements and procedures in the correct order to produce the desired results Debugging The process of removing all syntax and logical errors from the program Syntax errors are discovered through compilation Logical errors are discovered through testing 5

Features of Object-Oriented Programming Class Languages A category of objects or a type of object Describes the attributes and behaviors of every object that is an instance, or object, of that class Object An instance of a class Contains its own set of attribute values 6

The C# Programming Language Developed as an object-oriented and componentoriented language Part of Microsoft Visual Studio 2012 Allows every piece of data to be treated as an object and to consistently employ the principles of objectoriented programming Contains a GUI interface that makes it similar to Visual Basic 7

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 8

Writing a C# Program that Produces Output class literal string namespace method argument 9

Writing a C# Program that Produces Output Namespace (cont d.) Provides a way to group similar classes Can be used to avoid naming conflicts in large projects 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 10

Writing a C# Program that Produces Output Access modifier (cont d.) Defines the circumstances under which the method can be accessed Public, private, protected, internal 11

Writing a C# Program that Produces Output Keywords (cont d.) Predefined and reserved identifiers that have special meaning to the compiler 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 12

Selecting Identifiers Requirements Must begin with an underscore, an at sign (@), or a 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 13

14

Selecting Identifiers (cont d.) 15

Selecting Identifiers (cont d.) 16

Selecting Identifiers (cont d.) 17

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 18

Adding Program Comments (cont d.) 19

Using the System Namespace 20

Using the System Namespace (cont d.) 21

Compiling and Executing a C# Program Steps for viewing a program s output Compile source code into intermediate language (IL) The 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) 22

Compiling Code from the Command Prompt Example of an operating system error message Command csc stands for C Sharp compiler Location of csc.exe c:\windows\microsoft.net\framework\vx.x.xxx 23

Compiling Code from the Command Prompt (cont d.) Example of a command line generated error message Program error messages start with the program name followed by the line number and position within the line of the error 24

Compiling Code Using the Visual Studio IDE Advantages of using the Visual Studio IDE Some of the code you need is already created for you auto-complete The code is displayed in color Some syntax errors are caught as you type 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 25

Compiling Code Using the Visual Studio IDE (cont d.) 26

Deciding Which Environment 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 The code automatically generated by the IDE is very helpful when writing a GUI 27

You Do It (cont d.) 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 28

You Do It (cont d.) 29

You Do It (cont d.) Compiling and Executing a Program Using the Visual Studio IDE (cont d.) 30

You Do It (cont d.) 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! */ 31