Introduction:

  • In this article we will explain how to use internal modifier or specifier  in c# or What internal modifier or why use internal modifier in c# or how to hides variables and methods to accessing another  namespace  or Application in c# with example.

  • Description:

 

The internal keyword is used to specify the internal access specifier for the variables and functions. Its hide 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 same application or assembly. It is the default access specifiers for a class in C# programming.

  • Let's see a simple Example of internal modifier

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace AccessSpecifiers
{
    class User
    {
        internal string designation = "Software Developer";
        internal void GetUser()
        {
            Console.WriteLine("Name : Aditya Kumar Patel");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            User User = new User();
            //Accessing internal  function 
            User.GetUser(); 
            //Accessing internal  variable 
            Console.WriteLine("Designation :" + User.designation);
            Console.ReadLine();
        }
    }
}

 

Output:

what is internal access modifier in c#

I hope this article will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like