前言
本文会先分别解释protected和internal的作用,在解释protected internal联合修饰符的作用,因为它们联合在一起是或的含义。
protected
英文解释:The type or member can be accessed only by code in the same class, or in a class that is derived from that class.
说明: 在继承链上的类里面都可以使用,但出了类,比如说下面Main中这样的用法就是不对的:
using System;
using static System.Console;
using System.Threading;
namespace ConsoleApp_Test
{
class Program
{
static void Main(string[] args)
{
DerivedStudent.DoHomeWork(); // 错误用法,会报错访问级别不够
ReadKey();
}
}
public class Student
{
protected static void DoHomeWork()
{
WriteLine("Do Work!");
}
}
public class DerivedStudent : Student