Class Members
Contents |
Once a class is created it must be populated with data and methods in order to make it useful as a programming construct. The data and methods which act upon the data are referred to as members.
Members
There are several types of members that a class can have. These are:
- Fields - instances of objects that are considered part of a class, normally holding class data.
- Properties - methods on a class that are accessed as if they were fields on that class. A property can provide protection for a class field to keep it from being changed without the object's knowledge. For a more detailed understanding see Fields and Properties.
- Methods - these define the actions that a class can perform by actioning a series of statements. Methods can take parameters that provide input data, and can return output data through parameters. Methods can also return a value directly, without using a parameter.
- Events - a way of providing notifications about occurrences, such as button clicks or the successful completion of a method, to other objects. Events are defined and triggered using delegates. (See the 70-536 entry for Events and check out the article by Jeff Sudeth and read the sample chapter "Delegates and Events" by Jesse Liberty).
- Delegates - a type safe container of one or more function pointers. (See the 70-536 entry for Delegates and check out the article by Jeff Sudeth).
- Operators - these are terms or symbols such as +, *, <, and so on that perform operations on operands. Operators can be redefined to perform operations on custom data types.
- Indexers - these allow an object to be indexed in a manner similar to arrays.
- Constructors - methods that are called when the object is first created. They are often used to initialize the object's data.
- Destructors - methods that are called by the runtime execution engine when the object is about to be removed from memory. They are generally used to make sure that any resources which need to be released are handled appropriately.
- Constants - data members that are known at compile time.
Modifiers
Each type of modifier may or may not be available to a member. The modifiers may include:
abstract - indicates that a class is intended only to be a base class of other classes.
extern - used to declare a method that is implemented externally (as in a DLL file).
new - hides a member inherited from a base class.
override - required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.
readonly - fields that are read-only and are initialized at declaration or in a constructor.
sealed - overrides a method in a base class, but itself cannot be overridden further in any derived class.
static – a member that doesn't belong to an instance of the class, but belongs to the class itself.
virtual - used to modify a method, property, indexer or event declaration, and allow it to be overridden in a derived class.
volatile - fields that are modifiable by the environment, a separate thread, or hardware.
Accessibility
public - any item in the current assembly or any assembly that references the class, can access this member.
protected - access is limited to the containing class or types derived from the containing class.
internal - any item in the current assembly can access this member.
protected internal - access is limited to the current assembly or types derived from the containing class.
private - access is limited to the containing class.
MSDN references
|

