Page 80 - CSharp/C#
P. 80
same class and derived classes only:
public class Foo()
{
protected void SomeFooMethod()
{
//do something
}
protected class Thing
{
private string blah;
public int N { get; set; }
}
}
public class Bar() : Foo
{
private void someBarMethod()
{
SomeFooMethod(); // inside derived class
var thing = new Thing(); // can use nested class
}
}
public class Baz()
{
private void someBazMethod()
{
var foo = new Foo();
foo.SomeFooMethod(); //not accessible due to protected modifier
}
}
protected internal
The protected internal keyword marks field, methods, properties and nested classes for use
inside the same assembly or derived classes in another assembly:
Assembly 1
public class Foo
{
public string MyPublicProperty { get; set; }
protected internal string MyProtectedInternalProperty { get; set; }
protected internal class MyProtectedInternalNestedClass
{
private string blah;
public int N { get; set; }
}
}
public class Bar
{
void MyMethod1()
{
Foo foo = new Foo();
https://riptutorial.com/ 26

