Introduction To Programming: Creating and Running Your First C# Program
Introduction To Programming: Creating and Running Your First C# Program
2
What is Computer Programming?
Define: Computer Programming
Definition by Google
4
Programming Phases
Define a task/problem = Specification
Plan your solution
◦ Find suitable algorithm to solve it
◦ Find suitable data structures to use
Write code
= Design
Fix program error (bugs)
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;
class HelloCSharp
The { symbol should be
{ alone on a new line.
static void Main()
{
Console.WriteLine("Hello, C#");
}
}
class HelloCSharp {
static
void Main( ) { Console
. WriteLine ("Hello, C#" )
;Console.
WriteLine ( "Hello again"
) ;}}
10
What is "C#“ ?
11
What You Need to Program?
Knowledge of a programming language C# -
Task to solve
12
Your First C# Program
What is .NET
Framework?
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
Inside .NET Framework
Building blocks of .NET Framework
17
Framework Class Library
Framework Class Library (FCL) ◦ Web applications (dynamic Web sites)
developers: workflow
applications
18
What is Visual Studio?
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
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, …)
21
Visual Studio – Example
22
Visual Studio
COMPILING, RUNNING AND DEBUGGING C#
PROGRAMS
Creating New Console Application
File New Project ...
Choose C# console application
24
Creating New Console Application (2)
Choose project directory and name
Visual Studio creates some source code for
you
25
Creating New Console Application (2)
Namespace
not required Some imports
are not required
Class name
should be
changed
26
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)
27
Running Programs
The process of running application includes:
◦ Compiling (if project not compiled)
◦ Starting the application
28
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
29
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
30
Visual Studio
COMPILING, RUNNING AND DEBUGGING C#
PROGRAMS
What is MSDN
Library?
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/
33
MSDN Library
34
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
35
MSDN Library
BROWSING AND SEARCHING DOCUMENTATION
Live Demo
Introduction to Programming
Questions?
Exercises
1. Familiarize yourself with:
38
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.
39
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.