Object Oriented Programing
[OOP]
Session
Content
1. Exception Handling
2. Access Modifiers
3. Enum
4. Struct
5. What Is OOP
Exception Handling
// Exceptions
// 1. System Exceptions
//// 1.1 Format Exception
//// 1.2 Index Out Of Range Exception
//// 1.3 Null Reference Exception
//// 1.4 Invalid Operation Exception
//// 1.5 Arithmetic Exception
//// 1.5.1 Divided By Zero Exception
//// 1.5.2 Overflow Exception
// 2. Application Exception
Access Modifiers
C# Keywords Indicate The Accessibility Scope
Access Modifiers
C# Keywords Indicate The Accessibility Scope
1. Private
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public
From
Less
Accessible
To
Wider
Namesp
ace
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside
Namespace ?
1. Class
2. Struct
3. Interface
4. Enum
Access Modifier Allowed Inside
Namespace ?
1. Internal [Default]
2. Public
Class Or
Struct
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside The Struct Or Class
1. Attributes [Fields] => Member Variable
2. Functions [Constructor , Getter Setter , Method]
3. Properties [Full Property , Automatic Property , Indexer]
4. Events
Class Or
Struct
C# Keywords Indicate The Accessibility Scope
Access Modifier Allowed
Inside Struct?
1. Private [Default]
2. Internal
3. Public
Access Modifier Allowed
Inside Class?
1. Private [Default]
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public
Interfa
ce
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside The Interface ?
1. Signature For Property => C# 7.0
2. Signature For Method => C# 7.0
3. Default Implemented Method => C# 8.0 Feature .Net Core 3.1 [2019]
Enum
An enum type is a special data type that enables for a variable to be a set
of predefined constants
Delete
Write
Read
Execute
Bool [] Permissions = new bool[4];
Write Read Execute Delete
T F T F
1 bool : 1 byte
Bool[4] : 4 byte
1 byte : 8 bits
0 1
Write Read Execute Delete
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
128 64 32 16 8 4 2 1
Delete => 1
Execute => 2
Read => 4
Write => 8
Delete
Write
Read
Execute
Write Read Execute Delete
1 0 0 0
0 1 1 1
1 1 1 1
0 1 0 1
128 64 32 16 8 4 2 1
Delete => 1
Execute => 2
Read => 4
Write => 8
Decimal
8
7
15
5
Delete => 1
Execute => 2
Read => 4
Write => 8
1 => Delete
2 => Execute
3 => Delete , Execute
4 => Read
5 => Delete , Read
6 => Execute , Read
8 => Write
7 => Delete , Execute , Read
9 => Delete , Write
10 => Execute ,Write
11 => Delete , Execute , Write
12 => Read , Write
13 => Delete , Read , Write
14 => Execute , Read , Write
15 => Delete , Execute , Read , Write
Bitwise Operators :
& => And
| => OR
^ => XOR
// If You Want To Add Permission [Read] => Do [XOR] Operation
employee.Permissions = employee.Permissions ^ Permission.Read;
3 ^ 4
0 0 1 1
^
0 1 0 0
0 1 1 1 => 7
employee.Permissions = (Permission)3 ; // Delete , Execute
Console.WriteLine(employee.Permissions); // Delete , Execute , Read
// If You Want To Remove | Deny Permission [Read] => Do [XOR] Operation
employee.Permissions = employee.Permissions ^ Permission.Read;
7 ^ 4
0 1 1 1
^
0 1 0 0
0 0 1 1 => 3
employee.Permissions & Permission.Delete
3 & 1
0 0 1 1
&
0 0 0 1
0 0 0 1 => 1
// If You Want To Check Whether a Specific Permission is Existed or Not => DO [AND] Operation
Console.WriteLine(employee.Permissions); // Delete , Execute
(employee.Permissions & Permission.Delete) == permission.Delete // True
Bitwise Operators :
& => And
| => OR
^ => XOR
employee.Permissions = employee.Permissions | Permission.Delete
3 | 1
0 0 1 1
|
0 0 0 1
0 0 1 1 => 3
// If You Want To Add Permission => DO [OR] Operation
// OR => If Permission Existed -> Do Nothing
=> If Permission is not Existed -> Will Be Added
Console.WriteLine(employee.Permissions); // Delete , Execute
Bitwise Operators :
& => And
| => OR
^ => XOR
employee.Permissions = employee.Permissions | Permission.Read
3 | 4
0 0 1 1
|
0 1 0 0
0 1 1 1 => 7
Struct
Stru
ct
Stack
Point P1 ;
Y
X
8 Bytes
P1 = new Point(1,2);
2
1
Struct
● Value Type
● Support Encapsulation and
Overloading in Polymorphism
● Doesn’t Support Inheritance
● 3 Access Modifier Allowed
Inside It
● If You Defined a user defined
Constructor , Compiler Will
always Generate
Parameterless Constructor
OOP Definition
OOP Consists Of 4 Pillars :
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction

object oriented programming using C# programming langauge 01

  • 1.
  • 2.
    Session Content 1. Exception Handling 2.Access Modifiers 3. Enum 4. Struct 5. What Is OOP
  • 3.
    Exception Handling // Exceptions //1. System Exceptions //// 1.1 Format Exception //// 1.2 Index Out Of Range Exception //// 1.3 Null Reference Exception //// 1.4 Invalid Operation Exception //// 1.5 Arithmetic Exception //// 1.5.1 Divided By Zero Exception //// 1.5.2 Overflow Exception // 2. Application Exception
  • 4.
    Access Modifiers C# KeywordsIndicate The Accessibility Scope
  • 5.
    Access Modifiers C# KeywordsIndicate The Accessibility Scope 1. Private 2. Private Protected 3. Protected 4. Internal 5. Protected Internal 6. Public From Less Accessible To Wider
  • 6.
    Namesp ace C# Keywords IndicateThe Accessibility Scope What You Can Write Inside Namespace ? 1. Class 2. Struct 3. Interface 4. Enum Access Modifier Allowed Inside Namespace ? 1. Internal [Default] 2. Public
  • 7.
    Class Or Struct C# KeywordsIndicate The Accessibility Scope What You Can Write Inside The Struct Or Class 1. Attributes [Fields] => Member Variable 2. Functions [Constructor , Getter Setter , Method] 3. Properties [Full Property , Automatic Property , Indexer] 4. Events
  • 8.
    Class Or Struct C# KeywordsIndicate The Accessibility Scope Access Modifier Allowed Inside Struct? 1. Private [Default] 2. Internal 3. Public Access Modifier Allowed Inside Class? 1. Private [Default] 2. Private Protected 3. Protected 4. Internal 5. Protected Internal 6. Public
  • 9.
    Interfa ce C# Keywords IndicateThe Accessibility Scope What You Can Write Inside The Interface ? 1. Signature For Property => C# 7.0 2. Signature For Method => C# 7.0 3. Default Implemented Method => C# 8.0 Feature .Net Core 3.1 [2019]
  • 10.
    Enum An enum typeis a special data type that enables for a variable to be a set of predefined constants
  • 11.
    Delete Write Read Execute Bool [] Permissions= new bool[4]; Write Read Execute Delete T F T F 1 bool : 1 byte Bool[4] : 4 byte 1 byte : 8 bits 0 1 Write Read Execute Delete 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 128 64 32 16 8 4 2 1 Delete => 1 Execute => 2 Read => 4 Write => 8
  • 12.
    Delete Write Read Execute Write Read ExecuteDelete 1 0 0 0 0 1 1 1 1 1 1 1 0 1 0 1 128 64 32 16 8 4 2 1 Delete => 1 Execute => 2 Read => 4 Write => 8 Decimal 8 7 15 5
  • 13.
    Delete => 1 Execute=> 2 Read => 4 Write => 8 1 => Delete 2 => Execute 3 => Delete , Execute 4 => Read 5 => Delete , Read 6 => Execute , Read 8 => Write 7 => Delete , Execute , Read 9 => Delete , Write 10 => Execute ,Write 11 => Delete , Execute , Write 12 => Read , Write 13 => Delete , Read , Write 14 => Execute , Read , Write 15 => Delete , Execute , Read , Write
  • 14.
    Bitwise Operators : &=> And | => OR ^ => XOR // If You Want To Add Permission [Read] => Do [XOR] Operation employee.Permissions = employee.Permissions ^ Permission.Read; 3 ^ 4 0 0 1 1 ^ 0 1 0 0 0 1 1 1 => 7 employee.Permissions = (Permission)3 ; // Delete , Execute Console.WriteLine(employee.Permissions); // Delete , Execute , Read // If You Want To Remove | Deny Permission [Read] => Do [XOR] Operation employee.Permissions = employee.Permissions ^ Permission.Read; 7 ^ 4 0 1 1 1 ^ 0 1 0 0 0 0 1 1 => 3
  • 15.
    employee.Permissions & Permission.Delete 3& 1 0 0 1 1 & 0 0 0 1 0 0 0 1 => 1 // If You Want To Check Whether a Specific Permission is Existed or Not => DO [AND] Operation Console.WriteLine(employee.Permissions); // Delete , Execute (employee.Permissions & Permission.Delete) == permission.Delete // True Bitwise Operators : & => And | => OR ^ => XOR
  • 16.
    employee.Permissions = employee.Permissions| Permission.Delete 3 | 1 0 0 1 1 | 0 0 0 1 0 0 1 1 => 3 // If You Want To Add Permission => DO [OR] Operation // OR => If Permission Existed -> Do Nothing => If Permission is not Existed -> Will Be Added Console.WriteLine(employee.Permissions); // Delete , Execute Bitwise Operators : & => And | => OR ^ => XOR employee.Permissions = employee.Permissions | Permission.Read 3 | 4 0 0 1 1 | 0 1 0 0 0 1 1 1 => 7
  • 17.
  • 18.
    Stru ct Stack Point P1 ; Y X 8Bytes P1 = new Point(1,2); 2 1
  • 19.
    Struct ● Value Type ●Support Encapsulation and Overloading in Polymorphism ● Doesn’t Support Inheritance ● 3 Access Modifier Allowed Inside It ● If You Defined a user defined Constructor , Compiler Will always Generate Parameterless Constructor
  • 20.
    OOP Definition OOP ConsistsOf 4 Pillars : 1. Encapsulation 2. Inheritance 3. Polymorphism 4. Abstraction