Inaccessible Member

Why Trust Techopedia

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.

Advertisements

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.

Advertisements

Related Terms

Margaret Rouse
Editor

Margaret jest nagradzaną technical writerką, nauczycielką i wykładowczynią. Jest znana z tego, że potrafi w prostych słowach pzybliżyć złożone pojęcia techniczne słuchaczom ze świata biznesu. Od dwudziestu lat jej definicje pojęć z dziedziny IT są publikowane przez Que w encyklopedii terminów technologicznych, a także cytowane w artykułach ukazujących się w New York Times, w magazynie Time, USA Today, ZDNet, a także w magazynach PC i Discovery. Margaret dołączyła do zespołu Techopedii w roku 2011. Margaret lubi pomagać znaleźć wspólny język specjalistom ze świata biznesu i IT. W swojej pracy, jak sama mówi, buduje mosty między tymi dwiema domenami, w ten…