Access modifiers in C#

Had some confusion with NHibernate and its proxy generation. It couldn’t create proxies for an item with an internal property. It told me to mark the property as protected internal. Turned out my understanding of protected internal was wrong.

These are the choices for accessibility in C#. They are roughly in order of decreasing accessibility. However, the internal keyword messes things up a bit.

public
Any class in any assembly can access something with this modifier.

protected internal
Any class in the same assembly can access this. In other assemblies, only child classes can access this.

internal
Only classes in the same assembly can access this.

protected
Only child classes can access this, regardless of assembly.

private
Can only be accessed within the class where it is defined.

Some posts/articles that helped:

About Evan Gates

Switching from Visual Studio and C# to vim and ruby.
This entry was posted in uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply