What Does Inaccessible Member Mean?
An inaccessible member, in the context of C#, is a member that cannot be accessed by a specific type. An inaccessible member that cannot be accessed by one type can be accessible by another type.
An inaccessible member may obtain the accessibility level that controls its usage from other code in the assembly in which it is declared, or from other assemblies.
A member of a type is designed to be inaccessible from certain types for the purpose of encapsulation. Encapsulation of data helps to protect data within the object from accidental corruption as well as hiding unnecessary implementation details from the object’s user.
Techopedia Explains Inaccessible Member
The accessibility of a member of a type is determined by the type in which it resides and the access modifier specified to it during its declaration. The following are the access modifiers used to specify accessibility:
- Public: Access to both the current assembly and an external assembly that references it.
- Private: Access is limited to the containing type.
- Protected: Access is limited to the containing class or types derived from the containing type.
- Internal: Access is limited to current assembly only.
- Protected internal: Access is limited to current assembly or to the types derived from the containing class.
For example, a type can be declared with a method that has a protected modifier so that it is inaccessible outside the class but accessible to its derived classes.
Not all access modifiers can be used in all contexts by all types. When a member of a type does not include an access modifier during its declaration, its default accessibility is private.
As per the accessibility constraint in C#, several constructs require a type to be at least as accessible as a member or another type. Additionally, if the member is a method, delegate, or indexer, the return type and parameter types must be at least as accessible as the member itself. Use of an inaccessible member will result in a compile time error.