Sunday, December 11, 2011

Designing a class 4: Member access modifiers

Members within a class can be restricted from which those members can be accessed. Those restrictions can be applied by prefixing the access modifiers while declaring them.

 

Access Modifiers

Private: private members are accessible only from the code blocks within the class.

Keyword

[VB] Private

[CS] private

Protected: protected members are accessible from the code blocks of the class and the code blocks of its derived class.

Keyword

[VB] Protected

[CS] protected

Friend/Internal: friend/internal members are accessible from the code blocks anywhere within the assembly where the class resides.

Keyword

[VB] Friend

[CS] internal

Protected friend/Protected internal: these members can be accessed from the code blocks anywhere within the assembly where the class resides and the code blocks from the derived classes declared in other assemblies.

Keyword

[VB] Protected friend

[CS] protected internal

Public: public members does not have any restrictions

Keyword

[VB] Public

[CS] public

No comments:

Post a Comment