All C#5
All C#5
All C#5
1 Introduc on@Tt_001................................................................................ 2
1.1 Programming Paradigms : .......................................................... 2
1.2 Pre Dot Net: ............................................................................. 2
1.3 With Dot Net 2002 : .................................................................. 2
1.4 Net Code Compila on Steps ...................................................... 3
2 Chapther1 ............................................................................................................. 4
2.1 Comments_Regions .................................................................. 4
2.2 Errors ...................................................................................... 4
2.3 Naming_Convension ................................................................. 4
2.4 Variables ................................................................................. 5
2.5 DataType ................................................................................. 5
Value Type Reference Type ................................................. 5
2.6 DataTypes................................................................................ 6
2.6.1 ValueType .................................................................................................. 6
2.6.2 Reference Type.................................................................................... 6
2.7 Object ..................................................................................... 7
#references type (+) 7
2.8 Frac ons and Discard ................................................................ 8
2.9 Value Type Cas ng .................................................................... 8
2.9.1 Implicit cas ng..................................................................................... 8
2.9.2 Explicit cas ng...................................................................................... 8
2.9.3 parse (method) ................................................................................... 9
2.9.4 convert(class) ........................................................................................ 9
3 Chapter2 .................................................................................................................10
3.1 Operators: ..............................................................................10
3.1.1 Operators priority ...........................................................................12
3.2 Block Scope ............................................................................12
3.3 String format...........................................................................13
3.4 Control Statements ..................................................................13
3.4.1 Condi onal Statements ...........................................................13
3.4.2 Loop Statements ..............................................................................15
3.5 String .....................................................................................16
3.6 StringBuilder ...........................................................................17
0
C#
3.7 Deep copy && shallow copy......................................................18
3.7.1 DeepCopy .................................................................................................18
3.7.2 shallowCopy ..........................................................................................18
4 Chapter 3 ................................................................................................................19
4.1 Array ......................................................................................19
4.1.1 One D Array ............................................................................................19
4.1.2 Two 2D Array ........................................................................................20
4.1.3 Array Methods ....................................................................................22
4.2 Boxing / UnBoxing ...................................................................23
4.2.1 Boxing ..........................................................................................................23
4.2.2 UnBoxing...................................................................................................23
4.3 Nullable Types .........................................................................24
|Page1
C#
1 Introduc on@Tt_001
1.1 Programming Paradigms :
Linear/Sequen al
Structure
OOP
3. C#
4. J# (Disconnected)
5. F#
|Page2
C#
1.4 Net Code Compila on Steps
JIT compiler
CLR
Overhead at Runtime : Jitting
Common language runtime (CLR or just runtime) 1. Jit Compiler (64 Bit) so it is very fast
2. Jitting Happen per Function call
is an environment that runs the code and
3. Jitting For first call only as long as
provides services that make the development process easier.program is not terminated
|Page3
C#
2 Chapther1
2.1 Comments_Regions
1): // Single Line comment
#end region
2.2 Errors
1): syntax error iint x = 5; so error
4): Warning not error but this code not used or there ⚠
___________________________________________________________________________
2.3 Naming_Convension
firstName Camal Case
FirstName Pascal Case used in C#
First-Name Kabab Case Angular
___________________________________________________________________________
|Page4
C#
2.4 Variables
Steps: Data Type Name Value Address
EX:_ int x = 5; Address CLR Managed code
DataType + Name + Value CLR Reseve (Address) at memory
_________________________________________
2.5 DataType
Common Type System (CTS)
VB
CLS common language Specifica on vh
F# C#
CLS
|Page5
C#
2.6 DataTypes
2.6.1 ValueType
Output = 5
|Page6
C#
2.7 Object
#-------------------------------------#
#references type (+) :_
Where p1 point & p2 point = two address
|Page7
C#
2.8 Frac ons and Discard
Solu on
#------------------------------------------------#
|Page8
C#
2.9.3 parse (method)
convert String to any type ///Because console back string
#---------------------------------------------------#
2.9.4 convert(class)
any Data Type to Data Type
NoAllow
& If possible, it will be converted
|Page9
C#
3 Chapter2
3.1 Operators:
-- - += != && &
* -= >= || ^
/ *= <= <<
% /= > >>
%= <
| P a g e 10
C#
| P a g e 11
C#
3.1.1 Operators priority
Example:
| P a g e 12
C#
3.3 String format
Step1: but Immutable Type Can`t change A er crea on
| P a g e 13
C#
By switch:
#Note:
In case of a condi on, it is be er to use an IF condi on
#------------------------------------------------------------------#
But if it exists Equality using switch because make Jump table
#jump table :_ Standing on the step is required
| P a g e 14
C#
3.4.2 Loop Statements
Different between for / foreach ( for can revise in array /but for each can`t)
# but Same performance, same speed !
3): do-while
# flage true or false /// why: !flag because out false while out but true new return
| P a g e 15
C#
3.5 String
# String name ;
CLR Allocate 4 byte at Stack for Reference
CLR Allocate 0 byte at Heap
# Name = “Tharwat”; // Syntex Sugar
CLR Allocate required at butes at heap 2*7 byte
CLR Reference name Allocate object at heap (Address)
| P a g e 16
C#
3.6 StringBuilder
| P a g e 17
C#
3.7 Deep copy && shallow copy
3.7.1 DeepCopy
3.7.2 shallowCopy
#---------------------------------------------------------------#
Clone Copy the data and add it to the new view with a new address for the data
| P a g e 18
C#
4 Chapter 3
4.1 Array
4.1.1 One D Array
There 4 Ways to Write Array
2) way
3) way
#-------------------------------------------------------#
#---------------------------------------------------------#
#Dispaly Array using 1 for Loob:
| P a g e 20
C#
2): Jagged Array // number of rows not Equal number of columns;
#--> Jagged Array is one Dimension Array of other Array with Different Sizes;
#-----------------------------------------------------------------------------#
| P a g e 21
C#
4.1.3 Array Methods
#->1<-# Class Mumber Methods
#---------------------------Copy----------------------------#
#----------------------ConstrainedCopy----------------------#
#------------------------Create_Instance-----------------------------#
| P a g e 22
C#
#->2<-#Object Mumber Methods [Non Sta c Methods]
$-->{ Copyto , Element at , where , append , any , Getlength, Set value}$
#----------------------------------------------------------------------------------------#
4.2 Boxing / UnBoxing
4.2.1 Boxing
Cas ng Value Type Reference Type
4.2.2 UnBoxing
Cas ng From reference Type to Value Type
| P a g e 23
C#
4.3 Nullable Types
Syntax suger
More sugar
| P a g e 24
C#
4.4 Null Propaga on
| P a g e 25
C#
5 Chapter 4
5.1 Introduc on to Func on
5.1.1 What you can write in NameSpace
1) Class
2) Struct
3) Enum
4) Interface
5.1.2 What you can write in Class
1) Func ons (Methods)
2) Date (A ributes)
//Main Is Entry Point
# Class on the same program, not necessary to write the name of program.
# in print can`t use \ but can write @“ant\thing” or write \\
# \n Then a new line
# \t Then a space between two sentences
| P a g e 26
C#
5.2 Paramaters
5.2.1 Passing by Value
| P a g e 27
C#
5.2.2 Passing by Reference
# When we make a referance here, it doesn't make a copy, it
doesn't take a Address on each other #
| P a g e 28
C#
5.3 Reference Type parameter
5.3.1 Passing by Value
This is not protec ve Code
| P a g e 29
C#
5.3.2 Passing by reference
| P a g e 30
C#
5.4 Passing By Out Parameter
Before using OutPut parameter :_
can’t using two return solving the problem
| P a g e 31
C#
5.5 Params
Main
| P a g e 32