Internal vs. Private Access Modifiers

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

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

7条回答
  •  广开言路
    2020-11-27 09:44

    internal members are visible to all code in the assembly they are declared in.
    (And to other assemblies referenced using the [InternalsVisibleTo] attribute)

    private members are visible only to the declaring class. (including nested classes)

    An outer (non-nested) class cannot be declared private, as there is no containing scope to make it private to.

    To answer the question you forgot to ask, protected members are like private members, but are also visible in all classes that inherit the declaring type. (But only on an expression of at least the type of the current class)

提交回复
热议问题