Kurdistan Region Government – Iraq
Ministry of Higher Education and
Scientific Research
Erbil polytechnic University
Koya Technical Institute
IT Department / Morning
Introduction Programming C#
Prepared by:
Taib Tarq
Supervised by:
Mr. Wshyar Omer
1
Outline :
Learn C#.................................................................................................................. 3
What is C#?..............................................................................................................3
C# is used for:..........................................................................................................3
C# Variables............................................................................................................ 4
User Input ............................................................................................................... 5
C# If ... Else.............................................................................................................6
Loops....................................................................................................................... 7
For Loops.................................................................................................................7
While Loop.............................................................................................................8
Do/While Loop........................................................................................................8
References................................................................................................................9
2
Learn C#
C# (C-Sharp) is a programming language developed by Microsoft that runs on
the .NET Framework.
C# is used to develop web apps, desktop apps, mobile apps, games and much
more.
What is C#?
C# is pronounced "C-Sharp".
It is an object-oriented programming language created by Microsoft that runs on
the .NET Framework.
C# has roots from the C family, and the language is close to other popular
languages like C++ and Java.
The first version was released in year 2002. The latest version, C# 11, was released
in November 2022.
C# is used for:
Mobile applications Games
Desktop applications VR
Web applications Database applications
Web services And much, much more!
3
Web sites
C# Variables
Variables are containers for storing data values.
In C#, there are different types of variables (defined with different keywords), for
example:
int - stores integers (whole numbers), without decimals, such as 123 or -123
double - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by
single quotes
string - stores text, such as "Hello World". String values are surrounded by double
quotes
bool - stores values with two states: true or false
Example
4
User Input
Now we will use Console.ReadLine() to get user input.
In thefollowingexample, the user can input his or hers
nameand age, which is stored in thevariable nameand
age.Then we print thevalue of nameand age:
5
C# If ... Else
C# if else statement is a common selection statement. The if else in the
C# statement checks a Boolean expression and executes the code based
on if the expression is true or false.
6
Loops
Loops can execute a block of code as long as a specified condition is reached.
Loops are handy because they save time, reduce errors, and they make code more
readable.
Types of loop
For Loop
While Loop
Do…while Loop
Nested Loop
For Loop
A for loop is a repetition control structure that allows you to efficiently write a
loop that needs to execute a specific number of times.
7
While Loop
The while loop loops through a block of code as long as a specified condition
Do/While Loop
The do/while loop is a variant of the while loop. This loop will execute the code
block once, before checking if the condition is true, then it will repeat the loop as
long as the condition is true.
8
References
The Book of Programming
A group of experts in the field of programming around the world