01 introduction to programming

39
Introduction to Introduction to Programming Programming Creating and Running Your First C# Creating and Running Your First C# Program Program Svetlin Nakov Svetlin Nakov Telerik Telerik Corporation Corporation www.telerik. com

Upload: maznabili

Post on 26-Jun-2015

54 views

Category:

Technology


3 download

DESCRIPTION

Introduction of programming

TRANSCRIPT

Page 1: 01 Introduction to programming

Introduction to Introduction to ProgrammingProgramming

Creating and Running Your First C# Creating and Running Your First C# ProgramProgram

Svetlin NakovSvetlin NakovTelerik Telerik

CorporationCorporationwww.telerik.com

Page 2: 01 Introduction to programming

Table of ContentsTable of Contents

1.1. What is Computer Programming?What is Computer Programming?

2.2. Your First C# ProgramYour First C# Program

3.3. What is .NET Framework?What is .NET Framework?

4.4. What is Visual Studio?What is Visual Studio?

5.5. What is MSDN Library?What is MSDN Library?

2

Page 3: 01 Introduction to programming

What is What is Computer Computer

Programming?Programming?

Page 4: 01 Introduction to programming

Define: Computer Define: Computer ProgrammingProgramming

Computer programmingComputer programming: : creating a sequence of creating a sequence of instructions to enable the instructions to enable the computer to do somethingcomputer to do something

Definition by Definition by GoogleGoogle

4

Page 5: 01 Introduction to programming

Programming PhasesProgramming Phases

Define a task/problemDefine a task/problem Plan your solutionPlan your solution

Find suitable algorithm to solve itFind suitable algorithm to solve it

Find suitable data structures to useFind suitable data structures to use Write codeWrite code Fix program error (bugs)Fix program error (bugs)

Make your customer happyMake your customer happy

= Specification= Specification

= Design= Design

= Implementation= Implementation

= Testing & Debugging= Testing & Debugging

= Deployment= Deployment

5

Page 6: 01 Introduction to programming

Your First C# Your First C# ProgramProgram

Page 7: 01 Introduction to programming

First Look at C#First Look at C#

Sample C# program:Sample C# program:

using System;using System;

class HelloCSharpclass HelloCSharp{{ static void Main()static void Main() {{ Console.WriteLine("Hello, C#");Console.WriteLine("Hello, C#"); }}}}

77

Page 8: 01 Introduction to programming

C# Code – How It C# Code – How It Works?Works?

using System;using System;

class HelloCSharpclass HelloCSharp{{ static void Main()static void Main() {{ Console.WriteLine("Hello, C#");Console.WriteLine("Hello, C#"); }}}}

Include the Include the standard standard

namespace namespace ""SystemSystem""

Define a class Define a class called called

""HelloCSharpHelloCSharp""

Define Define the the Main() Main() method method – the program – the program

entry pointentry point

Print a text on the Print a text on the console by calling the console by calling the method "method "WriteLineWriteLine" of " of

the class "the class "ConsoleConsole"" 8

Page 9: 01 Introduction to programming

C# Code Should Be Well C# Code Should Be Well FormattedFormatted

using System;using System;

class HelloCSharpclass HelloCSharp{{ static void Main()static void Main() {{ Console.WriteLine("Hello, C#");Console.WriteLine("Hello, C#"); }}}}

The The {{ symbol symbol should be alone should be alone on a new line.on a new line.

The block The block after the after the {{ symbol symbol should be should be

indented by a indented by a TABTAB..

The The }} symbol symbol should be should be under the under the

corresponding corresponding {{..

Class names should use Class names should use PascalCasePascalCase and start with and start with

a a CAPITALCAPITAL letter. letter.

9

Page 10: 01 Introduction to programming

Example of Bad Example of Bad FormattingFormatting

using using SystemSystem ;;

class HelloCSharp class HelloCSharp { {

static static void Main( ) void Main( ) { Console . WriteLine ("Hello, { Console . WriteLine ("Hello, C#" ) ;Console.C#" ) ;Console. WriteLine ( "Hello WriteLine ( "Hello again"again" ) ) ;}};}}

Such Such formatting formatting makes the makes the

source code source code unreadable.unreadable.

10

Page 11: 01 Introduction to programming

What is "C#"?What is "C#"? Programming languageProgramming language

A syntax that allow to give A syntax that allow to give instructions to the computerinstructions to the computer

C# features:C# features:

New cutting edge languageNew cutting edge language

Extremely powerfulExtremely powerful

Easy to learnEasy to learn

Easy to read and understandEasy to read and understand

Object-orientedObject-oriented11

Page 12: 01 Introduction to programming

What You Need to What You Need to Program?Program?

Knowledge of a programming Knowledge of a programming languagelanguage C#C#

Task to solveTask to solve Development environment, compilers, Development environment, compilers,

SDKSDK Visual StudioVisual Studio, , .NET Framework SDK.NET Framework SDK

Set of useful standard classesSet of useful standard classes Microsoft .NET Framework FCLMicrosoft .NET Framework FCL

Help documentationHelp documentation MSDN LibraryMSDN Library

12

Page 13: 01 Introduction to programming

Your First C# ProgramYour First C# ProgramLive DemoLive Demo

Page 14: 01 Introduction to programming

What is .NET What is .NET Framework?Framework?

Page 15: 01 Introduction to programming

What is .NET What is .NET Framework?Framework?

Environment for execution of .NET Environment for execution of .NET programsprograms

Powerful library of classesPowerful library of classes Programming modelProgramming model Common execution engine for many Common execution engine for many

programming languagesprogramming languages C#C#

Visual Basic .NETVisual Basic .NET

Managed C++Managed C++

... and many others... and many others 15

Page 16: 01 Introduction to programming

Operating System (OS)Operating System (OS)

Common Language Runtime (CLR)Common Language Runtime (CLR)

Base Class Library (BCL)Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)ADO.NET, LINQ and XML (Data Tier)

WCF and WWF (Communication and Workflow Tier)WCF and WWF (Communication and Workflow Tier)

ASP.NETASP.NETWeb Forms, MVC, AJAXWeb Forms, MVC, AJAXMobile Internet ToolkitMobile Internet Toolkit

WindowsWindowsFormsForms WPFWPF SilverlightSilverlight

C#C# C++C++VB.NETVB.NET J#J# F#F# JScriptJScriptPerlPerlDelphiDelphi ……

Inside .NET FrameworkInside .NET Framework Building blocks of .NET FrameworkBuilding blocks of .NET Framework

FCFCLL

CLCLRR

16

Page 17: 01 Introduction to programming

CLR – The Heart of .NET CLR – The Heart of .NET FrameworkFramework

Common Language Runtime (CLR)Common Language Runtime (CLR) Managed execution environmentManaged execution environment

Executes .NET applicationsExecutes .NET applications

Controls the execution processControls the execution process

Automatic memory managementAutomatic memory management ((garbage collectiongarbage collection))

Programming languages integrationProgramming languages integration

Multiple versions support for Multiple versions support for assembliesassemblies

Integrated type safety and securityIntegrated type safety and security

CLRCLR

17

Page 18: 01 Introduction to programming

Framework Class Framework Class LibraryLibrary

Framework Class Library (FCL)Framework Class Library (FCL) Provides basic functionality to developers:Provides basic functionality to developers:

Console applicationsConsole applications

WPF and Silverlight rich-media applicationsWPF and Silverlight rich-media applications

Windows Forms GUI applicationsWindows Forms GUI applications

Web applications (dynamic Web sites)Web applications (dynamic Web sites)

Web servicesWeb services, , communication and workflowcommunication and workflow

Server & desktop applicationsServer & desktop applications

Applications for mobile devicesApplications for mobile devices

18

Page 19: 01 Introduction to programming

What is Visual Studio?What is Visual Studio?

Page 20: 01 Introduction to programming

Visual StudioVisual Studio Visual Studio – Integrated Visual Studio – Integrated

Development Environment (IDE)Development Environment (IDE) Development tool that helps us to:Development tool that helps us to:

Write codeWrite code

Design user interfaceDesign user interface

Compile codeCompile code

Execute / test / debug applicationsExecute / test / debug applications

Browse the helpBrowse the help

Manage project's filesManage project's files20

Page 21: 01 Introduction to programming

Benefits of Visual Benefits of Visual StudioStudio

Single tool for:Single tool for:

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

Using different technologies (Web, WPF, …)Using different technologies (Web, WPF, …)

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

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

Very easy to use!Very easy to use!21

Page 22: 01 Introduction to programming

Visual Studio – ExampleVisual Studio – Example

22

Page 23: 01 Introduction to programming

Visual StudioVisual StudioCompiling, Running and Debugging C# Compiling, Running and Debugging C#

Programs Programs

Page 24: 01 Introduction to programming

Creating New Console Creating New Console ApplicationApplication

1.1. File File New New Project ... Project ...

2.2. Choose C# console applicationChoose C# console application

3.3. Choose project directory and nameChoose project directory and name

24

Page 25: 01 Introduction to programming

Creating New Console Creating New Console Application (2)Application (2)

4.4. Visual Studio creates some source Visual Studio creates some source code for youcode for you

NamespaNamespace not ce not

requiredrequired

Class Class name name should should

be be changedchanged

Some Some imports are imports are

not not requiredrequired

25

Page 26: 01 Introduction to programming

Compiling Source CodeCompiling Source Code The process of The process of compilingcompiling includes: includes:

Syntactic checksSyntactic checks

Type safety checksType safety checks

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

Creating of executable files Creating of executable files (assemblies)(assemblies)

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

PressingPressing [[F6]F6] oror [Shift+Ctrl+B][Shift+Ctrl+B] 26

Page 27: 01 Introduction to programming

Running ProgramsRunning Programs The process of The process of runningrunning application application

includes:includes:

Compiling (if project not compiled)Compiling (if project not compiled)

Starting the applicationStarting the application

You can run application by:You can run application by:

Using Using Debug->Start Debug->Start menumenu

By pressing By pressing [F5][F5] or or [Ctrl+F5][Ctrl+F5]

* NOTE: Not all types of projects are * NOTE: Not all types of projects are able to be started!able to be started! 27

Page 28: 01 Introduction to programming

Debugging The CodeDebugging The Code The process of The process of debuggingdebugging

application includes:application includes: Spotting an errorSpotting an error

Finding the lines of code Finding the lines of code that cause the errorthat cause the error

Fixing the codeFixing the code

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

Iterative and continuous Iterative and continuous processprocess 28

Page 29: 01 Introduction to programming

Debugging in Visual Debugging in Visual StudioStudio

Visual Studio has built-in debuggerVisual Studio has built-in debugger It provides:It provides:

BreakpointsBreakpoints

Ability to trace the code executionAbility to trace the code execution

Ability to inspect variables at Ability to inspect variables at runtimeruntime

29

Page 30: 01 Introduction to programming

Visual StudioVisual StudioCompiling, Running and Debugging C# Compiling, Running and Debugging C#

Programs Programs LiveLive DemoDemo

Page 31: 01 Introduction to programming

What is What is MSDN MSDN

Library?Library?

Page 32: 01 Introduction to programming

What is MSDN Library?What is MSDN Library? Complete documentation of all Complete documentation of all

classes and their functionalityclasses and their functionality With descriptions of all methods, With descriptions of all methods,

properties, events, etc.properties, events, etc.

With code examplesWith code examples Related articlesRelated articles Library of samplesLibrary of samples Use local copy or the Web version Use local copy or the Web version

at at http://msdn.microsoft.com/32

Page 33: 01 Introduction to programming

MSDN LibraryMSDN Library

33

Page 34: 01 Introduction to programming

How to Use MSDN How to Use MSDN Library?Library?

Offline versionOffline version

Use the table of contentsUse the table of contents

Use the alphabetical indexUse the alphabetical index

Search for phrase or keywordSearch for phrase or keyword

Filter by technologyFilter by technology

Browse your favorite articlesBrowse your favorite articles

Online versionOnline version

Use the built-in searchUse the built-in search34

Page 35: 01 Introduction to programming

MSDN LibraryMSDN LibraryBrowsing and Searching DocumentationBrowsing and Searching Documentation

Live DemoLive Demo

Page 36: 01 Introduction to programming

Introduction to Introduction to ProgrammingProgramming

QuestionsQuestions??

http://academy.telerik.com

Page 37: 01 Introduction to programming

ExercisesExercises

1.1. Familiarize yourself with:Familiarize yourself with:

Microsoft Visual StudioMicrosoft Visual Studio

Microsoft Developer Network (MSDN) Library Microsoft Developer Network (MSDN) Library DocumentationDocumentation

Find information about Find information about Console.WriteLine()Console.WriteLine()

method.method.

2.2. Create, compile and run a “Hello C#” Create, compile and run a “Hello C#” console application.console application.

3.3. Modify the application to print your name.Modify the application to print your name.

4.4. Write a program to print the numbers 1, Write a program to print the numbers 1, 101 and 1001.101 and 1001.

37

Page 38: 01 Introduction to programming

Exercises (2)Exercises (2)

5.5. Install at home:Install at home:

1.1. Microsoft .NET Framework Microsoft .NET Framework

2.2. Microsoft Visual Studio (or Visual C# Microsoft Visual Studio (or Visual C#

Express)Express)

3.3. Microsoft Developer Network (MSDN)Microsoft Developer Network (MSDN)

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

7.7. Create a console application that prints the Create a console application that prints the current date and time.current date and time.

8.8. Create a console application that Create a console application that calculates and prints the square of the calculates and prints the square of the number 12345.number 12345. 38

Page 39: 01 Introduction to programming

Exercises (3)Exercises (3)

9.9. Write a program that prints the first 10 Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, members of the sequence: 2, -3, 4, -5, 6, -7, ...6, -7, ...

10.10.Provide a short list with information Provide a short list with information about the most popular programming about the most popular programming languages. How do they differ from C#?languages. How do they differ from C#?

11.11.Describe the difference between C# Describe the difference between C# and .NET Framework.and .NET Framework.

12.12.* Write a program to read your age * Write a program to read your age from the console and print how old you from the console and print how old you will be after 10 years.will be after 10 years.

*NOTE: If you have any difficulties, *NOTE: If you have any difficulties, search in Google.search in Google.

39