Lecture 01 C# Basics Dr. Eng. Ibrahim El-Nahry. 2 Welcome to CSC-102 Instructor:Dr.Eng. Ibrahim El-nahry Office:Building Com.Bldg, Room 13 Office Phone:……………….

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Objectives You should be able to describe: Introduction to Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 1: Introduction
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
The Java Programming Language
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide To UNIX Using Linux Third Edition
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Introduction to C Programming
Chapter 1 Introduction.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
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.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Chapter 1 Introduction.
A First Program Using C#
Chapter 1 Programming Languages. Application Development: Top 10 Programming Languages to Keep You Employed 1. Java 2. C# 3. C++ 4. JavaScript 5. Visual.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Microsoft Visual Basic 2005: Reloaded Second Edition
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Java Language and SW Dev’t
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
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.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
The Java Programming Language
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Introduction to programming in the Java programming language.
Introduction to Computer and Programing Thanachat Thanomkulabut.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
Introduction to .NET Framework
CSC201: Computer Programming
Lecture 1 Introduction Richard Gesick.
C# and the .NET Framework
Java programming lecture one
Advanced Programming Lecture 02: Introduction to C# Apps
Chapter 1: Computer Systems
Chapter 3 – Introduction to C# Programming
Focus of the Course Object-Oriented Software Development
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
CS313T Advanced Programming language
Presentation transcript:

Lecture 01 C# Basics Dr. Eng. Ibrahim El-Nahry

2 Welcome to CSC-102 Instructor:Dr.Eng. Ibrahim El-nahry Office:Building Com.Bldg, Room 13 Office Phone:………………. Schedule and Office Hours: DaySatSunMonTueWed Time 09:00 – 10:00 10:00-11:00 09:00 – 10:00 10:00-11:00 09:00 – 10:00 10:00-11:00 09:00 – 10:00 10:00-11:00 09:00 – 10:00 10:00-11:00 Location Room-1107 Room-1132 Room- 13 Room-1107 Room-1132 Room-13 Room-1107 Room-1132 BuildingComm. Bldg.Faculty Bldg.Comm. Bldg.Faculty Bldg.Comm. Bldg.

3 Grading Policy Classwork10% Laboratory 20% Midterm Exam I15% Midterm Exam II15% Final Exam40%

4 Why CSC-102 using C#? C# (pronounced "See Sharp") is a multi-purpose computer programming language suitable for all development needs. C# is a simple, modern, object-oriented, and type-safe programming language. C# is standardized by ECMA International as the ECMA-334 standard and by ISO/IEC as the ISO/IEC standard. C# is an object-oriented language, but C# further includes support for component-oriented programming. Several C# features aid in the construction of robust and durable applications

5 Course Description This course provides an introduction to object- oriented programming. Topics include classes and objects: a deeper look, inheritance, polymorphism, interfaces & operator overloading, exception handling, graphical user interface concepts, strings, files and streams.

6 Which Books will be Used? Harvey M. Deitel and Paul J. Deitel, Visual C# 2010: How to Program, Fourth Edition, Deitel & Associates, Joyce Farrell, Object-Oriented Programming Using C++, Third Edition, Thomson – Course Technology, 2009

7 Create and use classes and objects. Declare and create an array of objects. Understand inheritance and software reusability. Design and implement systems that are easily extensible and maintainable with polymorphism. Understand exceptions and error handling. Create and manipulate immutable character string objects of class String. Create, read, write, and update files. CSC-102 Objectives

8 Introduction

9 Programming Language Levels Each type of CPU has its own specific machine language Other levels were created to satisfy different objectives, e.g., make it easier for a human being to write programs machine language assembly language intermediate language high-level language

10 Example Machine Code Fragment A number specifies what action the computer should take.

11 Example Assembly Code Fragment movl (%edx,%eax), %ecx movl 12(%ebp), %eax leal 0(,%eax,4), %edx movl $nodes, %eax movl (%edx,%eax), %eax fldl (%ecx) fsubl (%eax) movl 8(%ebp), %eax leal 0(,%eax,4), %edx movl $nodes, %eax movl (%edx,%eax), %ecx movl 12(%ebp), %eax leal 0(,%eax,4), %edx movl $nodes, %eax Symbols to help programmers to remember the words.

12 Example C++/C#/Java Code Fragment bool DetermineNeighbor(int i, int j) { double distanceX = (nodes[i].x - nodes[j].x); double distanceY = (nodes[i].y - nodes[j].y); double distanceSquare = disx * disx + disy * disy; double distance = sqrt(distanceSquare); if (distance < radius) return true; else return false; } You do not need to understand the exact meaning of this program, just the feeling.

13 C# Features No pointers required Automatic memory management through garbage collection Formal syntactic constructs for enumerations, structures and class properties The C++ like ability to overload operators for a custom type, without the complexity Using a syntax very similar to C++ templates to build generics Full support for interface-based programming techniques Full support for aspect-oriented programming techniques via attributes

14 Programming Languages A program written in a high-level language must be translated into machine language before it can be executed on a particular type of CPU A compiler is a software tool which translates source code into a specific target language

15 C# Translation and Execution The C# compiler translates C# source code (.cs files) into a special representation called Microsoft Intermediate Language (MSIL) MSIL is not the machine language for any traditional CPU, but a virtual machine The Common Language Runtime (CLR) then interprets the MSIL file It uses a JIT/Jitter ( just-in-time) compiler to translate from MSIL format to machine code on the fly

16 C# Compilation and Execution C# source code MSIL C# compiler Machine code Just in time compiler

17 A Simple C# Program //=============================================== // This program prints a string called "Hello, World! ” //=============================================== using System; class HelloWorld { static void Main(string[] args) { Console.WriteLine( “ Hello, World! ” ); }

18 The starting point of the program is: This is known as the method Main A method is put inside a class A class may be put inside a namespace static void Main () {... starting point... } static void Main () {... starting point... } C# Beginning

19 C# Program Structure Program specifications (optional) //=============================================== // This program prints a string called "Hello, World! ” //=============================================== Library imports (optional) using System; Class and namespace definitions class HelloWorld { static void Main(string[] args) { Console.WriteLine( “ Hello, World! ” ); }

20 White Space and Comments White Space Includes spaces, newline characters, tabs, blank lines C# programs should be formatted to enhance readability, using consistent indentation! Comments Comments are ignored by the compiler: used only for human readers (i.e., inline documentation) Two types of comments Single-line comments use // … // this comment runs to the end of the line Multi-lines comments use /* … */ /* this comment runs to the terminating symbol, even across line breaks */

21 Identifiers Identifiers are the words that a programmer uses in a program An identifier can be made up of letters, digits, and the underscore character They cannot begin with a digit C# is case sensitive, therefore args and Args are different identifiers Sometimes we choose identifiers ourselves when writing a program (such as HelloWorld ) Sometimes we are using another programmer's code, so we use the identifiers that they chose (such as WriteLine ) using System; class HelloWorld { static void Main(string[] args) { Console.WriteLine(“Hello World!”); }

22 Identifiers: Keywords Often we use special identifiers called keywords that already have a predefined meaning in the language Example: class A keyword cannot be used in any other way All C# keywords are lowercase!

23 Namespaces Partition the name space to avoid name conflict! All.NET library code are organized using namespaces! By default, C# code is contained in the global namespace To refer to code within a namespace, must use qualified name (as in System.Console ) or import explicitly (as in using System; ) using System; class HelloWorld { static void Main(string[] args) { Console.WriteLine(“Hello World!”); } class HelloWorld { static void Main(string[] args) { System.Console.WriteLine(“Hello World!”); }

24 More on C# Program Structure In C#, a program is made up of Program specifications ( header comments, optional) Library imports (optional) One or more class (and namespace) definitions A class contains one or more methods A method contains program statements These terms will be explored in detail throughout the course

25

26 C# Program Structure: Class class HelloWorld {}{} // comments about the class class header class body Comments can be added almost anywhere

27 C# Classes Each class name is an identifier Can contain letters, digits, and underscores (_) Cannot start with digits Can start with the at symbol Convention: Class names are capitalized, with each additional English word capitalized as well (e.g., MyFirstProgram ) Class bodies start with a left brace ({) Class bodies end with a right brace (})

28 C# Program Structure: Method class HelloWorld {}{} // comments about the class static void Main (string[] args) {}{} // comments about the method Console.Write(“Hello World!”); Console.WriteLine(“This is from CS112!”);

29 C# Method and Statements Methods Building blocks of a program The Main method Each console or windows application must have exactly one (actually can have more, but it is unlikely that you will see or use) All programs start by executing the Main method Braces are used to start ({) and end (}) a method Statements Every statement must end in a semicolon ;

30 Main Method declaration 30 There are 4 ways to define Main function. We use the simplest one. static void Main() {...} static void Main(string[] args) {...} static int Main() {...} static int Main(string[] args) {...} C# Beginning

31

32 Inside method Main Variable declarations Statements static void Main(string[] args) { const double pi = ; int radius; double area; radius = int.Parse(Console.ReadLine()); area = pi*radius*radius; Console.WriteLine(area); } C# Beginning

33 Welcome1 Program Output 1 // Welcome1 2 // A program in C#. 3 4 using System; 5 6 class Welcome1 7 { 8 static void Main( string[] args ) 9 { 10 Console.WriteLine( "Welcome to C# Programming!" ); 11 } 12 } Welcome to C# Programming! These are two single line comments. They are ignored by the compiler and are only used to aid other programmers. They use the double slash (//) This is the using directive. It lets the compiler know that it should include the System namespace. This is a blank line. It means nothing to the compiler and is only used to add clarity to the program. This is the beginning of the Welcome1 class definition. It starts with the class keyword and then the name of the class. This is the start of the Main method. It instructs the program to do what you want. This is a statement. Console.WriteLine outputs a string.

34 Console Application vs. Window Application Console Application No visual component Only text input and output Run under Command Prompt or DOS Prompt Window Application Forms with many different input and output types Contains Graphical User Interfaces (GUI) GUIs make the input and output more user friendly! Message boxes Within the System.Windows.Forms namespace Used to prompt or display information to the user

35 Welcome4.cs Program Output 1 // Welcome4.cs 2 // Printing multiple lines in a dialog Box. 3 4 using System; 5 using System.Windows.Forms; 6 7 class Welcome4 8 { 9 static void Main( string[] args ) 10 { 11 MessageBox.Show( "Welcome\nto\nC#\nprogramming!" ); 12 } 13 } The System.Windows.Forms namespace allows the programmer to use the MessageBox class. This will display the contents in a message box as opposed to in the console window.

36 Syntax and Semantics The syntax rules of a language define how we can put symbols, reserved words, and identifiers together to make a valid program The semantics of a program statement define what that statement means (its purpose or role in a program) A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do

37 Errors A program can have three types of errors The compiler will find problems with syntax and other basic issues (compile-time errors) If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results (logical errors)

38 Summary C# is case-sensitive The starting point of the program is: This is known as the method Main A method is put inside a class A class may be put inside a namespace Use comments to aid understanding of your program Do not over comment A program can have three types of errors compile-time errors run-time errors logical errors