7
10/1/2018 EEES-403 (EEE-425) Programming Languages 1 2 Environment for execution of .NET programs Powerful library of classes Programming model Common execution engine for many programming languages C# Visual Basic .NET Managed C++ ... and many others 3 Version number CLR version Release date Support ended Development tool Included in Replaces Windows Windows Server 1.0 1.0 2002-02-13 2009-07-14 VS .NET XP SP1 N/A N/A 1.1 1.1 2003-04-24 2015-06-14 VS .NET 2003 XP SP2, SP3 2003 1.0 2.0 2.0 2005-11-07 2011-07-12 VS .NET 2005 N/A 2003 , 2003 R2 2008 SP2 , 2008 R2 SP1 N/A 3.0 2.0 2006-11-06 2011-07-12 Expression Blend Vista 2008 SP2 , 2008 R2 SP1 2.0 3.5 2.0 2007-11-19 N/A VS .NET 2008 7 , 8 , 8.1 , 10 2008 R2 SP1 2.0, 3.0 4.0 4 2010-04-12 2016-01-12 VS.2010 N/A N/A N/A 4.5 4 2012-08-15 2016-01-12 VS. 2012 8 2012 4.0 4.5.1 4 2013-10-17 2016-01-12 VS. 2013 8.1 2012 R2 4.0, 4.5 4.5.2 4 2014-05-05 N/A N/A N/A N/A 4.0–4.5.1 4.6 4 2015-07-20 N/A VS. 2015 10 v1507 N/A 4.0–4.5.2 4.6.1 4 2015-11-30 N/A VS .NET 2015 Update 1 10 v1511 N/A 4.0–4.6 4.6.2 4 2016-08-02 N/A 10 v1607 2016 4.0–4.6.1 4.7 4 2017-04-05 N/A VS. 2017 10 v1703 N/A 4.0–4.6.2 4.7.1 4 2017-10-17 N/A VS. 2017 10 v1709 2016 v1709 4.0–4.7 4.7.2 4 2018-04-30 N/A VS .2017 10 v1803 N/A 4.0–4.7.1 4.8 4 Developing N/A VS 2019 (Planning) 10 v1903 (Planning) N/A 4.0–4.7.2 Operating System (OS) Common Language Runtime (CLR) Base Class Library (BCL) ADO.NET, LINQ and XML (Data Tier) WCF and WWF (Communication and Workflow Tier) ASP.NET Web Forms, MVC, AJAX Mobile Internet Toolkit Windows Forms WPF Silverlight C# C++ VB.NET J# F# JScript Perl Delphi Building blocks of .NET Framework 5 FCL CLR The common classes that are used in many programs System.Console.WriteLine XML, Networking, Filesystem, Crypto, containers Can inherit from many of these classes Many languages run on .NET framework C#, C++, J#, Visual Basic even have Python (see IronPython)

Introduction to Programming · 10/2/2018  · Console.WriteLine("Hello, C#");}}} 25 C# was designed from the ground up to be an object-oriented, type-safe programming language. 26

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

10/1/2018

EEES-403 (EEE-425) Programming Languages 1

2

Environment for execution of .NET programs

Powerful library of classes

Programming model

Common execution engine for many programming languages◦ C#

◦ Visual Basic .NET

◦ Managed C++

◦ ... and many others

3

Version

number

CLR

version

Release

date

Support

ended

Development

tool

Included in

Replaces Windows Windows Server

1.0 1.0 2002-02-13 2009-07-14 VS .NET XP SP1 N/A N/A

1.1 1.1 2003-04-24 2015-06-14 VS .NET 2003 XP SP2, SP3 2003 1.0

2.0 2.0 2005-11-07 2011-07-12 VS .NET 2005 N/A2003, 2003 R2,[9] 2008

SP2, 2008 R2 SP1N/A

3.0 2.0 2006-11-06 2011-07-12Expression

BlendVista 2008 SP2, 2008 R2 SP1 2.0

3.5 2.0 2007-11-19 N/A VS .NET 2008 7, 8, 8.1, 10 2008 R2 SP1 2.0, 3.0

4.0 4 2010-04-12 2016-01-12 VS.2010 N/A N/A N/A

4.5 4 2012-08-15 2016-01-12 VS. 2012 8 2012 4.0

4.5.1 4 2013-10-17 2016-01-12 VS. 2013 8.1 2012 R2 4.0, 4.5

4.5.2 4 2014-05-05 N/A N/A N/A N/A 4.0–4.5.1

4.6 4 2015-07-20 N/A VS. 2015 10 v1507 N/A 4.0–4.5.2

4.6.1 4 2015-11-30 N/AVS .NET 2015

Update 110 v1511 N/A 4.0–4.6

4.6.2 4 2016-08-02 N/A 10 v1607 2016 4.0–4.6.1

4.7 4 2017-04-05 N/A VS. 2017 10 v1703 N/A 4.0–4.6.2

4.7.1 4 2017-10-17 N/A VS. 2017 10 v1709 2016 v1709 4.0–4.7

4.7.2 4 2018-04-30 N/A VS .2017 10 v1803 N/A 4.0–4.7.1

4.8 4 Developing N/AVS 2019

(Planning)

10 v1903

(Planning)N/A 4.0–4.7.2

Operating System (OS)

Common Language Runtime (CLR)

Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)

WCF and WWF (Communication and Workflow Tier)

ASP.NETWeb Forms, MVC, AJAXMobile Internet Toolkit

WindowsForms

WPF Silverlight

C# C++ VB.NET J# F# JScript Perl Delphi …

Building blocks of .NET Framework

5

FCL

CLR

The common classes that are used in many programs◦ System.Console.WriteLine◦ XML, Networking, Filesystem, Crypto, containers◦ Can inherit from many of these classes

Many languages run on .NET framework◦ C#, C++, J#, Visual Basic◦ even have Python (see IronPython)

10/1/2018

EEES-403 (EEE-425) Programming Languages 2

Common Language Runtime (CLR)◦ Managed execution environment

Executes .NET applications

Controls the execution process

◦ Automatic memory management (garbage collection)

◦ Programming languages integration

◦ Multiple versions support for assemblies

◦ Integrated type safety and security

8

CLR

Class Loader

MSIL to NativeCompilers (JIT)

CodeManager

GarbageCollector (GC)

Security Engine Debug Engine

Type Checker Exception Manager

Thread Support COM Marshaler

Base Class Library Support

From MSDN

CLR via C#, Jeffrey Richter

11

CLR is actually an implementation by Microsoft of the CLI (Common Language Infrastructure) .

CLI is an open specification.

CLR is really a platform specific implementation.

Framework Class Library (FCL)

◦ Provides basic functionality to developers:

Console applications

WPF(Windows Presentation Framework) and

Silverlight rich-media applications

Windows Forms GUI applications

Web applications (dynamic Web sites)

Web services, communication and workflow

Server & desktop applications

Applications for mobile devices

12

10/1/2018

EEES-403 (EEE-425) Programming Languages 3

13

Visual Studio – Integrated Development Environment (IDE)

Development tool that helps us to:

◦ Write code

◦ Design user interface

◦ Compile code

◦ Execute / test / debug applications

◦ Browse the help

◦ Manage project's files

14

Single tool for:

◦ Writing code in many languages (C#, VB, …)

◦ Using different technologies (Web, WPF, …)

◦ For different platforms (.NET CF, Silverlight, …)

Full integration of most development activities (coding, compiling, testing, debugging, deployment, version control, ...)

Very easy to use!

15 16

1. File New Project ...2. Choose C# console application3. Choose project directory and name

17

4. Visual Studio creates some source code for you

18

Class name should be

changed

Some imports are not required

Main Method

10/1/2018

EEES-403 (EEE-425) Programming Languages 4

The process of compiling includes:◦ Syntactic checks

◦ Type safety checks

◦ Translation of the source code to lower level language (MSIL)

◦ Creating of executable files (assemblies)

You can start compilation by◦ Using Build->Build Solution/Project

◦ Pressing [F6] or [Shift+Ctrl+B]

19

The process of running application includes:

◦ Compiling (if project not compiled)

◦ Starting the application

You can run application by:

◦ Using Debug->Start Debugging By pressing [F5]

or

Start Without Debegging By pressing [Ctrl+F5]

20

21

The process of debugging application includes:◦ Spotting an error

◦ Finding the lines of code that cause the error

◦ Fixing the code

◦ Testing to check if the error is gone and no errors are introduced

Iterative and continuous process

22

Visual Studio has built-in debugger

It provides:◦ Breakpoints

◦ Ability to trace the code execution

◦ Ability to inspect variables at runtime

23 24

10/1/2018

EEES-403 (EEE-425) Programming Languages 5

1-Sample C# Console Application program

using System;

namespace ConsoleApplication1{class HelloCSharp{

static void Main(string[] args){

Console.WriteLine("Hello, C#");}

}}

25

C# was designed from the ground up to be

an object-oriented, type-safe programming

language.

26

Programming in C#

Object-Oriented

27 28

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

29

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()

30

Methods and variables in OOP 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◦ 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

10/1/2018

EEES-403 (EEE-425) Programming Languages 6

31

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#

A constructor is a special member method whose task is to initialize the objects of its class.

It is special because its name is same as the class name.

The constructor is invoked whenever an object of its associated class is created.

It is called constructor because it constructs the values of data members of the class.

class add{

int m, n ;public : add (void) ;

------};

add :: add (void)

{

m = 0; n = 0;

}

• When a class contains a constructor, it is guaranteed that an object created by the class will be initialized automatically.

• add a ;

• Not only creates the object a of type add but also initializes its data members m and n to zero.

• They should be declared in the public section.

• They are invoked automatically when the objects are created.

• They do not have return types, not even void and they cannot return values.

• A destructor is used to destroy the objects that have been created by a constructor.

• Like constructor, the destructor is a member method whose name is the same as the class name but is preceded by a tilde.

class Foo {private ~Foo()

{ Console.WriteLine(“Destroyed {0}”, this);

}}

• A destructor never takes any argument nor does it return any value.

• It will be invoked implicitly by the compiler upon exit from the program – or block or function as the case may be – to clean up storage that is no longer accessible.

continue …

10/1/2018

EEES-403 (EEE-425) Programming Languages 7

37

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

38

To write a C# program that produces a line of console output, you must pass a literal string as a parameter to the 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

39

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

Questions?

40

1. Create console application that prints your first and last name.

2. Write a program to read your age from the console and print how old you

will be after 10 years.

3. Write a program to print numbers that starts from 1 thru n that is given

by user.

4. Create a console application that calculates power of n (nm) and prints the

result. (n and m are given by user)

5. Write a program that prints the first n (=> 10) members of the sequence

that starts with 2. (2, -3, 4, -5, 6, -7, n is given by user)

41