RSS

Objects Accessibility in C#.

02 May

Access Modifiers:

Access modifiers are keywords used to specify the declared accessibility of a member or a type. This section introduces the four access modifiers:

  • public
  • protected
  • internal
  • private

The following five accessibility levels can be specified using the access modifiers:

  • public: Access is not restricted.
  • protected: Access is limited to the containing class or types derived from the containing class.
  • internal: Access is limited to the current assembly.
  • protected internal: Access is limited to the current assembly or types derived from the containing class.
  • private: Access is limited to the containing type.

Accessibility Levels:

Only one access modifier is allowed for a member or type, except when you use the protected internal combination. Access modifiers are not allowed on namespaces. Namespaces have no access restrictions.

Depending on the context in which a member declaration occurs, only certain declared accessibilities are permitted. If no access modifier is specified in a member declaration, a default accessibility is used.

Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.

Nested types, which are members of other types, can have declared accessibilities as indicated in the following table.

Members of enum:

  • Default member accessibility is public.
  • Allowed declared accessibility of the member is none.

Members of class:

  • Default member accessibility is private.
  • Allowed declared accessibility of the member is public, internal, protected, protected internal, private.

Members of interface:

  • Default member accessibility is public.
  • Allowed declared accessibility of the member is none.

Members of struct:

  • Default member accessibility is private.
  • Allowed declared accessibility of the member is public, internal, private.

 
1 Comment

Posted by on May 2, 2012 in Visual C# . NET

 

Tags: , , , , , , , , , , , , ,

One response to “Objects Accessibility in C#.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: