Internal vs. Private Access Modifiers
C#中的internal
和private
修饰符有什么区别?
internal is for assembly scope (ie only accessible from code in the same .exe or .dll)
private is for class scope (ie accessible only from code in the same class).
Find an explanation below. You can check this link for more details - http://www.dotnetbull.com/2013/10/public-protected-private-internal-access-modifier-in-c.html
Private: - Private members are only accessible within the own type (Own class).
Internal: - Internal member are accessible only within the assembly by inheritance (its derived type) or by instance of class.
Reference :
dotnetbull - what is access modifier in c#
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)
For (hopefully) obvious reasons, an outer (non-nested) class cannot be declared private
.
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)
上一篇: Java中包私有类的优缺点?
下一篇: 内部与私人访问修改器