C# Internal Access Specifiers

In this chapter you will learn:
  • What is internal access specifier?
  • What is the boundary of internal access specifier?
  • How to use internal access specifier in C# programming?

The internal access specifier hides its member variables and methods from other classes and objects, that is resides in other namespace. The variable or classes that are declared with internal can be access by any member within application. It is the default access specifiers for a class in C# programming.

 

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Internal_Access_Specifier
{
    class access
    {
        // String Variable declared as internal
        internal string name;
        public void print()
        {
            Console.WriteLine("\nMy name is " + name);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            access ac = new access();
            Console.Write("Enter your name:\t");
            // Accepting value in internal variable
            ac.name = Console.ReadLine();
            ac.print();
            Console.ReadLine();
        }
    }
}

Output


Enter your name:     Steven Clark
My name is Steven Clark __

Summary

In this chapter you learned about internal access specifier, its boundary and scope and implementation in program. In next chapter you will learn protected internal access specifier in C#.

 

Share your thought