Public is the most accessible, such as name, everyone can know someone else's name, this is not a secret
Protected has lower access rights, only subclasses can access the protected property of the parent class. It's like Lao Tzu's property is inherited only by his son. If someone wants to ask: Hey, son. property = How much? Son will refuse, because son's property is inherited from the father, not to vent.
Private access to the lowest, only I can know. Like someone's bank card password. Only his own internal method of the class can access this property.
Internal access is limited to the same assembly. What do you call the same assembly? That is, in the same class library (DLL), the internal property of the class is the same as the public property, which can be accessed by anyone.
The access rights of protected internal are the protected and internal's set. This means that for other classes that belong to the same assembly, you can access him like the internal property, and for classes of different assemblies, only classes that inherit my class can access this property. Note: The order of protected and internal is not important.
Give me a chestnut:
Assembly 1:
public class A
{
Protected internal string x= "X";
}
public class D
{
public string func ()
{
A = new A ();
Return A.x;//ok, you can correctly access the
}
}
Assembly 2: DLL referencing assembly 1
public class B:a
{
public string func ()
{
Return X;//ok, you can correctly access the
}
}
public class C
{
public string func ()
{
A a= new A ();
Return a.x;//no, can not access to
}
}
Public, protected, private, internal, protected internal brief analysis