ECMA-334: 10.5.4 Accessibility constraints
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| C# Language Specification |
|
| © 2006 ECMA International |
10.5.4 Accessibility constraints
Several constructs in the C# language require a type to be at least as accessible as a member or another type.
A type T is said to be at least as accessible as a member or type M if the accessibility domain of T is a
superset of the accessibility domain of M. In other words, T is at least as accessible as M if T is accessible in
all contexts in which M is accessible.
The following accessibility constraints exist:
- The direct base class of a class type shall be at least as accessible as the class type itself.
- The explicit base interfaces of an interface type shall be at least as accessible as the interface type itself.
- The return type and parameter types of a delegate type shall be at least as accessible as the delegate type itself.
- The type of a constant shall be at least as accessible as the constant itself.
- The type of a field shall be at least as accessible as the field itself.
- The return type and parameter types of a method shall be at least as accessible as the method itself.
- The type of a property shall be at least as accessible as the property itself.
- The type of an event shall be at least as accessible as the event itself.
- The type and parameter types of an indexer shall be at least as accessible as the indexer itself.
- The return type and parameter types of an operator shall be at least as accessible as the operator itself.
- The parameter types of an instance constructor shall be at least as accessible as the instance constructor itself.
[Example: In the following code
class A {…} public class B: A {…}
the B class results in a compile-time error because A is not at least as accessible as B. end example]
[Example: Likewise, in the following code
class A {…} public class B { A F() {…} internal A G() {…} public A H() {…} }
the H method in B results in a compile-time error because the return type A is not at least as accessible as the
method. end example]