01. Introduction to Programming
Transcript of 01. Introduction to Programming
![Page 1: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/1.jpg)
Introduction to Programming
Creating and Running Your First C# Program
Svetlin NakovTelerik
Corporationwww.telerik.com
![Page 2: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/2.jpg)
Table of Contents1. What is Computer Programming?2. Your First C# Program3. What is .NET Framework?4. What is Visual Studio?5. What is MSDN Library?
2
![Page 3: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/3.jpg)
What is Computer
Programming?
![Page 4: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/4.jpg)
Define: Computer Programming
Computer programming: creating a sequence of instructions to enable the computer to do something
Definition by Google
4
![Page 5: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/5.jpg)
Programming Phases Define a task/problem Plan your solution
Find suitable algorithm to solve it Find suitable data structures to use
Write code Fix program error (bugs)
Make your customer happy
= Specification= Design
= Implementation
= Testing & Debugging= Deployment
5
![Page 6: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/6.jpg)
Your First C# Program
![Page 7: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/7.jpg)
First Look at C#Sample C# program:using System;
class HelloCSharp{ static void Main() { Console.WriteLine("Hello, C#"); }}
7
![Page 8: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/8.jpg)
C# Code – How It Works?
using System;
class HelloCSharp{ static void Main() { Console.WriteLine("Hello, C#"); }}
Include the standard
namespace "System"
Define a class called
"HelloCSharp"Define the
Main() method – the program
entry point
Print a text on the console by calling the method "WriteLine" of
the class "Console" 8
![Page 9: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/9.jpg)
C# Code Should Be Well Formatted
using System;
class HelloCSharp{ static void Main() { Console.WriteLine("Hello, C#"); }}
The { symbol should be alone on a new line.
The block after the { symbol should be
indented by a TAB.
The } symbol should be under the
corresponding {.
Class names should use PascalCase and start with a
CAPITAL letter.
9
![Page 10: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/10.jpg)
Example of Bad Formatting
using System ;
class HelloCSharp {
static void Main( ) { Console . WriteLine ("Hello, C#" ) ;Console. WriteLine ( "Hello again" ) ;}}
Such formatting makes the
source code unreadable.
10
![Page 11: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/11.jpg)
What is "C#"? Programming language
A syntax that allow to give instructions to the computer
C# features: New cutting edge language Extremely powerful Easy to learn Easy to read and understand Object-oriented
11
![Page 12: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/12.jpg)
What You Need to Program?
Knowledge of a programming language C#
Task to solve Development environment,
compilers, SDK Visual Studio, .NET Framework SDK
Set of useful standard classes Microsoft .NET Framework FCL
Help documentation MSDN Library
12
![Page 13: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/13.jpg)
Your First C# ProgramLive Demo
![Page 14: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/14.jpg)
What is .NET Framework?
![Page 15: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/15.jpg)
What is .NET Framework?
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
15
![Page 16: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/16.jpg)
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# JScriptPerlDelphi …
Inside .NET Framework Building blocks of .NET Framework
FCL
CLR
16
![Page 17: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/17.jpg)
CLR – The Heart of .NET Framework
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
CLR
17
![Page 18: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/18.jpg)
Framework Class Library
Framework Class Library (FCL) Provides basic functionality to developers:
Console applications WPF 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
18
![Page 19: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/19.jpg)
What is Visual Studio?
![Page 20: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/20.jpg)
Visual Studio 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
20
![Page 21: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/21.jpg)
Benefits of Visual Studio
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!
21
![Page 22: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/22.jpg)
Visual Studio – Example
22
![Page 23: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/23.jpg)
Visual StudioCompiling, Running and Debugging C#
Programs
![Page 24: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/24.jpg)
Creating New Console Application
1. File New Project ...2. Choose C# console application3. Choose project directory and name
24
![Page 25: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/25.jpg)
Creating New Console Application (2)
4. Visual Studio creates some source code for you
Namespace not
required
Class name should
be change
d
Some imports are not required
25
![Page 26: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/26.jpg)
Compiling Source Code 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]
26
![Page 27: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/27.jpg)
Running Programs The process of running application includes:
Compiling (if project not compiled) Starting the application
You can run application by: Using Debug->Start menu By pressing [F5] or [Ctrl+F5]
* NOTE: Not all types of projects are able to be started!
27
![Page 28: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/28.jpg)
Debugging The Code 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
28
![Page 29: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/29.jpg)
Debugging in Visual Studio
Visual Studio has built-in debugger It provides:
Breakpoints Ability to trace the code execution Ability to inspect variables at runtime
29
![Page 30: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/30.jpg)
Visual StudioCompiling, Running and Debugging C#
Programs Live Demo
![Page 31: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/31.jpg)
Visual Studio Blank Solution
Creating a Solution Without Projects
![Page 32: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/32.jpg)
What Is a Blank Solution?
A Visual Studio blank solution Solution with no projects in it
Projects to be added later What is the point?
Not making a project just to give proper name And not working in this project
![Page 33: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/33.jpg)
VS Blank Solution
33
![Page 34: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/34.jpg)
Visual Studio Blank Solution
Live Demo
![Page 35: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/35.jpg)
What is MSDN
Library?
![Page 36: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/36.jpg)
What is MSDN Library? Complete documentation of all classes and their functionality
With descriptions of all methods, properties, events, etc. With code examples
Related articles Library of samples Use local copy or the Web version at http://msdn.microsoft.com/
36
![Page 37: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/37.jpg)
MSDN Library
37
![Page 38: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/38.jpg)
How to Use MSDN Library?
Offline version Use the table of contents Use the alphabetical index Search for phrase or keyword Filter by technology Browse your favorite articles
Online version Use the built-in search
38
![Page 39: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/39.jpg)
MSDN LibraryBrowsing and Searching Documentation
Live Demo
![Page 41: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/41.jpg)
Exercises1. Familiarize yourself with:
Microsoft Visual Studio Microsoft Developer Network (MSDN)
Library Documentation Find information about Console.WriteLine()
method.2. Create, compile and run a “Hello C#”
console application.3. Modify the application to print your
name.4. Write a program to print the numbers 1,
101 and 1001.
41
![Page 42: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/42.jpg)
Exercises (2)5. Install at home:
1. Microsoft .NET Framework 2. Microsoft Visual Studio (or Visual C#
Express)3. Microsoft Developer Network (MSDN)
6. Create console application that prints your first and last name.
7. Create a console application that prints the current date and time.
8. Create a console application that calculates and prints the square of the number 12345.
42
![Page 43: 01. Introduction to Programming](https://reader036.fdocuments.in/reader036/viewer/2022081515/577ccd5c1a28ab9e788c1f57/html5/thumbnails/43.jpg)
Exercises (3)9. Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...10.Provide a short list with information about the most popular programming languages. How do they differ from C#?11.Describe the difference between C# and .NET Framework.12.* Write a program to read your age from the console and print how old you will be after 10 years.
*NOTE: If you have any difficulties, search in Google.
43