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
5.
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
6.
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
7.
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
8.
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]
9.
Enum
An enum typeis a special data type that enables for a variable to be a set
of predefined constants
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
Cla
ss
C# Keywords IndicateThe Accessibility Scope
Constructor in Class :
● If There is no User defined Constructor , Compiler Will Always
Generate Empty Parameterless constructor => Will do Nothing .
● If You defined a User defined Constructor , Compiler Will No
Longer Generate Empty Parameterless constructor.
Class VS
Struct
● ReferenceType ● Value Type
● Support 4 Pillars Of OOP ● Support Encapsulation and
Overloading in Polymorphism
● More Flexible
● Doesn’t Support Inheritance
● 6 Access Modifier Allowed
Inside It
● Does Support Inheritance
● 3 Access Modifier Allowed
Inside It
● If You Defined a user defined
Constructor , Compiler Will no
longer Generate Empty
Parameterless Constructor
● If You Defined a user defined
Constructor , Compiler Will
always Generate
Parameterless Constructor
Parent
1. Int X
2.Int Y
3. Ctor (int X , int Y)
4. Method Product [X* Y]
Child
1. Int X
2. Int Y
3. Int Z
4. Ctor (int X , int Y ,int Z)
5. Method Product [X* Y*Z]
Relationships Between
Classes
1. Inheritance2. Association
Class Product { }
Class OrderItem
{ Product Product ; }
Association Composition
Class Chair{}
Class Room
{ chair[] Chairs; }
Orderitem Has a Product
Association Aggregation
Room Has Chairs