Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Daniel Solis - Illustrated C# 2010 - 2010.pdf
Скачиваний:
16
Добавлен:
11.06.2015
Размер:
11.23 Mб
Скачать

CHAPTER 7 CLASSES AND INHERITANCE

Protected Internal Member Accessibility

Members marked protected internal are visible to all the classes that inherit from the class and also to all classes inside the assembly, as shown in Figure 7-20. Notice that the set of classes allowed access is the combined set of classes allowed by the protected modifier plus the set of classes allowed by the internal modifier. Notice that this is the union of protected and internal—not the intersection.

Figure 7-20. A protected internal member of a public class is visible to members of classes in the same

assembly or to members of classes derived from that class. It’s not visible to classes in other assemblies that

are not derived from the class.

Summary of Member Access Modifiers

The following two tables summarize the characteristics of the five member access levels. Table 7-1 lists the modifiers and gives an intuitive summary of the effects of the modifier.

Table 7-1. Member Access Modifiers

Modifier

Meaning

private

Accessible only within the class

internal

Accessible to all classes within this assembly

protected

Accessible to all classes derived from this class

protected internal

Accessible to all classes that are either derived from this class or declared

 

within this assembly

public

Accessible to any class

 

 

188

CHAPTER 7 CLASSES AND INHERITANCE

Figure 7-21 shows the relative accessibility of the five member access modifiers.

Figure 7-21. Relative accessibility of the various member access modifiers

Table 7-2 lists the access modifiers down the left side of the table and the categories of classes across the top. Derived refers to classes derived from the class declaring the member. Nonderived means classes not derived from the class declaring the member. A check in a cell means that the category of class can access members with the corresponding modifier.

Table 7-2. Summary of Member Accessibility

 

Classes in Same Assembly

Classes in Different Assembly

 

Non-Derived

Derived

Non-Derived

Derived

private

 

 

 

 

internal

 

 

 

 

protected

 

 

 

 

protected internal

 

 

 

 

public

 

 

 

 

189

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]