TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# Internal Keyword

This C# example program shows the effect of the internal modifier on a class.

Internal restricts access to members. There are many accessibility modifiers you can apply to a type.

The internal modifier, like others such as public and private, changes restrictions on where else the type can be accessed.

Example. To begin, we look at an example of the internal keyword in a C# program. You can add the internal modifier right before the keyword "class" to create an internal class. Any member type can also be modified with internal.

Tip: You can have internal fields, properties, or methods. This program can instantiate the Test type because it is in the same program.

Based on:

.NET 4.5

C# program that uses internal modifier

class Program
{
    static void Main()
    {
	// Can access the internal type in this program.
	Test test = new Test();
	test._a = 1;
    }
}

// Example of internal type.
internal class Test
{
    public int _a;
}

Specification. What does the internal modifier do exactly? The C# specification is concise on this question. It states that "The intuitive meaning of internal is 'access limited to this program.'"

So: In other words, no external program will be able to access the internal type.

Note: Accessibility in the C# language determines what regions of program text are allowed to access a specific member.

Use. As we have seen, the internal modifier has a specific purpose. What are some examples of its usage? Mainly, internal is for information hiding. This improves program quality by forcing programs to be modular.

This means that if you have a C# program that is contained in a different binary file, such as DLL or EXE, it will not successfully access the internal member. And this leads to improved maintainability.

Tip: In most programs, internal is not needed. For larger, more complex programs, it becomes more useful.

Also: The material on the public and private modifiers helps us understand internal and its effects.

PublicPrivate

Summary. The internal keyword enables information hiding across program boundaries. It is an accessibility modifier in the C# language. It is not needed in most programs. But it can improve the ease of maintenance on much larger programs.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf