The following are the access modifiers are availabale in .net framework
1. Public
2. Private
3.Friend(in C# it is known as internal)
4.Protected
5. Protected Friend
The main purpose of using scope modifiers are providing Security to the applications.when you want make an assmbely that can be used by various people in various applications on different computer then you want that member of assembly must be have some functions may be important not to show or access outside the assembly and same not
Here i will explain the types one by one.
1. PUBLIC
As the name specifies It can be accessed from anywhere. If a member of a class is defined as public then it can be access
anywhere in class as well as outside the class. Thus other objects can access can modify the public fields and can change
their values.
example
public str as string
public myfunciton () as integer
– define your function here
end function
2. PRIVATE
As the name suggest, It can’t be access outside the class. Its the private property of class and can be access only by the
members of the class.
example
Private str as string
Private myfunction() as integer
– define your function here
end function
3. FRIEND
Friends can be accessed by all classes within assembely but not from outside the assembely.
example
Friend sub myfunction()
– definne procedure here
end sub
4. PROTECTED
Protected variables can be used within the class as well as the classes that inherites this class.
example
Protected Myfunction() as integer
– define function here
end function
5 .PROTECTED FRIEND
The Protected Friend can be accessed by Members of the Assembely (Friend) or the inheriting class (Protected).
example
Protected Friend Myfunction() as integer
– define your function here
end function
As the name specifies It can be accessed from anywhere. If a member of a class is defined as public then it can be access
example
public str as string
public myfunciton () as integer
– define your function here
end function
As the name suggest, It can’t be access outside the class. Its the private property of class and can be access only by the
Private str as string
Private myfunction() as integer
– define your function here
end function
Friends can be accessed by all classes within assembely but not from outside the assembely.
Friend sub myfunction()
– definne procedure here
end sub
Protected variables can be used within the class as well as the classes that inherites this class.
Protected Myfunction() as integer
– define function here
end function
Protected Friend Myfunction() as integer
– define your function here
end function
No comments:
Post a Comment