Você está na página 1de 43

Introduction to

Programming
Creating and Running Your First C# Program

Svetlin Nakov
Telerik Corporation
www.telerik.com
1. What Table of Contents
is
Com
puter
Prog
ram
ming
?
2. Your
First
C#
Prog
ram 2
What is Computer
Programming?
Define: Computer Programming

Computer programming: creating a


sequence of instructions to enable the
computer to do something
Definition by Google

4
Programming Phases
 Define a task/problem = Specification
 Plan your solution = Design
 Find suitable algorithm to solve it
 Find suitable data structures to use
 Write code = Implementation
 Fix program error (bugs)
= Testing & Debugging
 Make your customer happy = Deployment
5
Your First C# Program
First Look at C#
Sample C# program:
using System;

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

7
C# Code – How It Works?
Include the standard Define a class called
namespace "System" "HelloCSharp"

using System; Define the Main()


class HelloCSharp method – the
{
static void Main()
program entry point
{
Console.WriteLine("Hello, C#");
}
}

Print a text on the console by


calling the method "WriteLine"
of the class "Console"
8
C# Code Should Be Well Formatted
Class names should use PascalCase
and start with a CAPITAL letter.
using System;

class HelloCSharp The { symbol should


{ be alone on a new line.
static void Main()
{
Console.WriteLine("Hello, C#");
}
}

The } symbol should The block after the


be under the { symbol should be
corresponding {. indented by a TAB.
9
Example of Bad Formatting
Such formatting
makes the source
code unreadable.
using
System
;

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

10
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
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
Your First C# Program
Live Demo
What is .NET
Framework?
 Enviro What is .NET Framework?
nmen
t for
execu
tion
of
.NET
progr
ams
 Power
ful
library
of 15
 Buildi Inside .NET Framework
ng
blocks
of
C# C++ VB.NET J# F# JScript Perl Delphi …
.NET
ASP.NET Windows
Frame
Web Forms, MVC, AJAX WPF Silverlight
Forms
work
Mobile Internet Toolkit
WCF and WWF (Communication and Workflow Tier) FCL
ADO.NET, LINQ and XML (Data Tier)
Base Class Library (BCL)
Common Language Runtime (CLR)
CLR

Operating System (OS)


16
CLR – The Heart of .NET
 Com
Framework
mon
Lang
uage
Runti CLR
me
(CLR)
 Man
age
d
exec
utio
n 17
 Fram Framework Class Library
ewor
k
Class
Librar
y
(FCL)
 Prov
ides
basi
c
func
tion 18
What is Visual Studio?
 Visual Visual Studio
Studi
o–
Integr
ated
Devel
opme
nt
Enviro
nmen
t (IDE)
 Devel
opme 20
 Single Benefits of Visual Studio
tool
for:
 Writ
ing
code
in
man
y
lang
uag
es
(C#, 21
Visual Studio – Example

22
Visual Studio
Compiling, Running and Debugging C# Programs
1. File Creating New Console Application

New

Proje
ct ...
2. Choo
se C#
conso
le
appli
catio
n
24
4. Visua Creating New Console Application (2)
l
Studi
o
Namespace
creat Some imports
not required are not required
es
some
sourc Class name
e should be
code changed
for
you

25
 The Compiling Source Code
proce
ss of
compi
ling
includ
es:
 Synt
actic
chec
ks
 Typ
e 26
 The Running Programs
proce
ss of
runni
ng
applic
ation
includ
es:
 Com
pilin
g (if
proj 27
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
 Visual Debugging in Visual Studio
Studi
o has
built-
in
debug
ger
 It
provid
es:
 Brea
kpoi
nts 29
Visual Studio
Compiling, Running and Debugging C# Programs
Live Demo
Visual Studio
Blank Solution
Creating a Solution
Without Projects
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
VS Blank Solution

33
Visual Studio
Blank Solution
Live Demo
What is MSDN
Library?
 Compl What is MSDN Library?
ete
docu
ment
ation
of all
classe
s and
their
functi
onalit
y
 Wit 36
MSDN Library

37
 Offlin How to Use MSDN Library?
e
versio
n
 Use
the
tabl
e of
cont
ents
 Use
the
alph 38
MSDN Library
Browsing and Searching Documentation
Live Demo
Introduction to Programming

Questions?

http://academy.telerik.com
Exercises
1. 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
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
9.Write Exercises (3)
a
progr
am
that
prints
the
first
10
mem
bers
of the
seque
nce:
*NOTE:
2, -3, If you have any difficulties, search in Google. 43

Você também pode gostar