Internal vs. Private Access Modifiers

后端 未结 7 1463
野性不改
野性不改 2020-11-27 09:30

What is the difference between the internal and private access modifiers in C#?

7条回答
  •  悲哀的现实
    2020-11-27 09:57

    internal members are accessible within the assembly (only accessible in the same project)

    private members are accessible within the same class

    Example for Beginners

    There are 2 projects in a solution (Project1, Project2) and Project1 has a reference to Project2.

    • Public method written in Project2 will be accessible in Project2 and the Project1
    • Internal method written in Project2 will be accessible in Project2 only but not in Project1
    • private method written in class1 of Project2 will only be accessible to the same class. It will neither be accessible in other classes of Project 2 not in Project 1.

提交回复
热议问题