--->Default access modifier of class and iterface is Internal. And private for class member. and methods->>
Static methods and class can not be overrideAccess modifiers are keywords used to specify the declared accessibility of a member or a type.Why to use access modifiers?Access modifiers are an integral part of object-oriented programming. They support the concept of encapsulation, which promotes the idea of hiding functionality. Access modifiers allow you to define who does or doesn't have access to certain features.In C# there are 5 different types of Access Modifiers.
Modifier
|
Description
|
public
|
There are no restrictions on accessing public members.
|
private
|
Access is limited to within the class definition. This is the default access modifier type if none is formally specified
|
protected
|
Access is limited to within the class definition and any class that inherits from the class
|
internal
|
Access is limited exclusively to classes defined within the current project assembly
|
protected internal
|
Access is limited to the current assembly and types derived from the containing class. All members in current project and all members in derived class can access the variables.
|
publicThe public keyword is an access modifier for types and type members. Public access is the most permissive access level.There are no restrictions on accessing public members.Accessibility:Can be accessed by objects of the classCan be accessed by derived
classesExample: In the following example num1 is direct access.
using System;
privatePrivate access is the least permissive access level.Private members are accessible only within the body of the class or the struct in which they are declared.Accessibility:Cannot be accessed by objectCannot be accessed by derived classesExample: In the following example num2 is not accessible outside the class.
using System;
Cannot be accessed by objectBy derived classesusing System;
namespace AccessModifiers
Inherited types, even though they belong to a different assembly, have access to the protected internal members.Types that reside in the same assembly, even if they are not derived from the type, also have access to the protected internal members.Default accessA default access level is used if no access modifier is specified in a member declaration.
The following list defines the default access modifier for certain C# types:enum: The default and only access modifier supported is public.
x
x
x
x
No comments:
Post a Comment