Internal Access Modifier in C#


In C#
The internal access modifier can be applied to
Classes and it’s member
Structure and it’s member
Enumeration
Interface

This way it is available to all the files within that assembly.
Particularly useful when creating software components.

It can be used in conjunction with protected to produce
protected internal access modifier
It can be applied only to
Class members

It is available withing it’s own assembly or to derived types.

For e.g.

Say if we create an Class Library which has a class like

namespace ClassLibrary1
{
public class MyClass

……

And then you create

Now we create new project say a windows application and add a refrence to that dll
And can create the object of that class lik

MyClass my=new MyClass();

this works fine,

now if we modify the definition of the class by replacing public with internal and update the assembly

namespace ClassLibrary1{
internal class MyClass

This time if we try to create the object of MyClass which is inside our referenced assembly
The error which we will get is

MyClass is inaccessible due to its protection level.

That’s why they are basically used in component development so that any other class couldn’t be able to access it i.e. create objects of it.

That’s it

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Please share your thoughts

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.