You must Sign In to post a response.
  • Category: .NET

    Practical usage of internal access specifier

    Hai All,

    May i know any practical usage of internal access specifier in the project

    what will happen we declare internal class and internal members and how to consume the internal member to another class

    Need clarification in this : can access the internal member within assembly
    I tried create one class library
    then create one sourcefile with classA and declare internal member for classA
    then create another sourcefile within same class library with name classB and tried to consume the classA internal member, it is not accessible.
    can you clear me the concept

    Thanks and Regards,
    A.L.Chellappan
  • #769040

    Hai A.L.Chellappan,
    The access specifier Internal is used many places like if you create a class or interface, by default it is internal. Of-course you can make it public later but the default behavior for these types is internal means the .net framework has written the definitions in such a way so that by default the types should be accessed within the application i.e. within the same assembly.
    It means when you create a class with the internal access specifier or modifier, it will be accessible only inside the project but not outside of the project by adding the reference.
    The same thing if you do creating a class with public and then create assembly and adding the reference into another project, will be accessible sue to its public nature.
    So the thumb rule is that- If any type is declared as internal, will be accessible to inside the application only and not in the other application by reference while the public members will be accessible to other applications by adding the reference and then try creating object etc.
    Hope it will be helpful to you.


    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #769053
    MSDN says
    "A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code. For example, a framework for building graphical user interfaces could provide Control and Form classes that cooperate using members with internal access. Since these members are internal, they are not exposed to code that is using the framework"
    in short This can be useful for creation of unit testing assemblies that are then allowed to call internal members of the assembly to be tested. Of course no other assemblies are granted this level of access, so when you release your system, encapsulation is maintained

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #769082
    Access specifier defines the accessibility of class member. It has 5 types public, Private , Protected , protected internal, internal . Example
     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    public class ProtBaseClass
    {
    protected int sum(int x, int y)
    {

    return x + y;
    }
    }


  • Sign In to post your comments