Youcef Madadi
Web and game development teacher
Coding with C# Part-1
1- Data & Computers
2- Data Types
4- Functions and parameters
5- Arrays
6- Loops & Conditions
3- Operations on Data
1-Data & Computers
What's Data ?
How computers treat data ?
how to use data ?
Data is a sequence of information that comes in different types
What's Data ?
How computers treat data ?
how to use a data ?
var name = data ;
var age = 21;
var name = "Youcef Madadi";
Example
2- Data Types
Numerical types.
symbolic types.
Reference types.
Boolean type.
Integer: all numbers in Z group. (use 16-32bit)
Float (real) : all numbers in R group (use 32bit)
double (real): same as float just use 64bit of memory.
Numerical types.
How to use a numerical Data
int age =21;
float physic = 15.5f;
double math = 2.25;
The reason why we write f in float is to see the difference between float and double, because both of them represent Real Numbers just the capacities are different .
symbolic types
to use symbols and characters we have a basic table called ASCII represented with numerical data too.
But C# language Uses Unicode .it's similar to ASCII just with more character ,and it's represented on 32bit.
to learn more check this web-page :
How to use a symbolic Data
char character = 'A';
char symbole = '@';
string word = "Hello";
string phrase = "Hello everyone";
Boolean type.
bool btrue = true;
bool bfalse = false;
they are used to catch conditions results or as flags.
Reference types.
int age = 10;
ref int _Age = ref age;
_Age = 20;
print(age);
print(_Age);
//output:
// 20
// 20
3- Operations on Data
Numerical operations.
symbolic operations.
Boolean operations.
Numerical operations.
int x = 5, y = 6;
int res1 = x + y; //res1 == 11
int res2 = x - y; //res2 == -1
int res3 = x * y; //res3 == 30
int res4 = x / y; //res4 == 0
int res5 = x % y; //res5 == 5
x++; //x == 6
y--; //y == 5
Numerical operations.
float x = 5.5f, y = 6.2f;
float res1 = x + y; //res1 == 11.7
float res2 = x - y; //res2 == -0.7
float res3 = x * y; //res3 == 34.1
float res4 = x / y; //res4 == 0.887
float res5 = x % y; //res5 == 5.5
double x = 5.5, y = 6.2;
double res1 = x + y; //res1 == 11.7
double res2 = x - y; //res2 == -0.7
double res3 = x * y; //res3 == 34.1
double res4 = x / y; //res4 == 0.887
double res5 = x % y; //res5 == 5.5
symbolic operations.
char x = '1', y = 'a';
char res1 = (char)90; //res1 == 'Z'
char res2 = (char)((int)x + 9); //res2 == '9'
char res3 = ++y; //res3 == 'b' and y == 'b'
char res3 = y++; //res4 == 'b' and y == 'c'
x++; //x == '2'
symbolic operations.
string x = "hello", y = "Game", z = "Devalopers";
string res1 = x + y; //res1 == "helloGame"
string res2 = x +" "+ y +" "+ z; //res2 == "hello Game Devalopers"
Boolean operations.
bool a = true, b = false;
bool res1 = a && b; //res1 == false (and operator)
bool res2 = a || b; //res2 == true (Or operator)
bool res3 = !a; //res3 == false (not operator)
Boolean operations.
int left = 5, right = 8;
bool res4 = left > right; //res4 == false
bool res5 = left < right; //res5 == true
bool res6 = left == right; //res6 == false
bool res7 = left >= right; //res7 == false
bool res8 = left <= right; //res8 == true
bool res9 = left != right; //res9 == true
Boolean operations.
string left = "hello", right = "game";
bool res10 = left == right; //res10 == false
bool res11 = left != right; //res11 == true
4- Functions and parameters
how to create a functions ?
functions Types.
functions parameters.
What are functions ?
What are functions ?
functions are a set of instruction that usually used many times.
how to create a functions ?
type functionName(){
.
.
instractions;
.
.
}
functions Types.
it depends on the return type.
if there is not type we write void
int two(){
return 2;
}
void two(){
print("two");
}
functions parameters.
functions parameters are values passed with the function to use them to get results.
{
int x=5,y=6,z;
z=addition(x,y);
}
int addition(int a,int b){
return a + b;
}
functions parameters.
we can change the values of the variables called within the function if we use the word ref.
{
int x=5,y=6,z;
@switch(ref x,ref y);
}
void @switch(ref int a,ref int b){
int tmp = a;
a = b;
b = tmp;
}
5- Arrays
what is an array ?
How to create an array ?
how to use an array?
what is an array ?
array is a set of data of the same type help us store more data using less variables.
How to create an array ?
type[] arrayName = new type[size];
int[] ages = new int[25];
Example :
string[] Names = new int[25];
how to use an array?
int[] ages = new int[24];
ages[0] = 21;
ages[1] = 19;
ages[2] = ages[0];
.
.
.
ages[24] = ages[10] + ages[22];
print(ages[12]);
6- Conditions & Loops
what are Conditions ?
if else, if else if.
switch case default
what are loops ?
for loop
while & do while loop
what are Conditions ?
Conditions are control structures used to check which instruction set to use.
if else, if else if
if (x >= y) {
print(x);
} else {
print(y);
}
if (x > y) {
print(x);
} else if(x == y){
print("equal");
} else {
print(y);
}
switch case default
int x = 5;
switch(x){
case 0: print("zero");
break;
case 1: print("one");
break;
.
.
case 5: print("five");
break;
.
.
default: print("above nine or bellow 0");
}
Switch case statements are a substitute for long if statements that compare a variable to several constant values.
what are loops ?
Loops are control structures used to repeat a given section of code a certain number of times or until a particular condition is met.
while & do while loop
Used for conditional repetition.
while(condition){
.
.
instructions;
.
.
}
int x=5
while(x>0){
x--;
print(x);
}
Example:
while & do while loop
Used for conditional repetition.
do{
.
.
instructions;
.
.
}while(condition);
int x=5
do{
print(x);
x--;
}while(x>0);
Example:
for loop
Used for iteration.
for(int i = begening; condition ; iteration){
.
.
instructions;
.
.
}
for(int i = 0; i<5 ; i++){
print(i);
}
Example:
int[] numbers = new int[25];
for(int i = 0; i<25 ; i++){
numbers[i] = i;
}
By Youcef Madadi