Compartir a través de


Members (C# Programming Guide)

Classes and structs have members that represent their data and behavior. A class's members include all the members declared in the class, along with all members (except constructors and destructors) declared in all classes in its inheritance hierarchy. Private members in base classes are inherited but are not accessible from derived classes.

The following table lists the kinds of members a class or struct may contain:

Member

Description

Fields (C# Programming Guide)

Fields are variables declared at class scope. A field may be a built-in numeric type or an instance of another class. For example, a calendar class may have a field that contains the current date.

Constants (C# Programming Guide)

Constants are fields or properties whose value is set at compile time and cannot be changed.

Properties (C# Programming Guide)

Properties are 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 knowledge of the object.

Methods (C# Programming Guide)

Methods define the actions that a class can perform. 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 (C# Programming Guide)

Events provide notifications about occurrences, such as button clicks or the successful completion of a method, to other objects. Events are defined and triggered by using delegates.

Operators (C# Programming Guide)

Overloaded operators are considered class members. When you overload an operator, you define it as a public static method in a class. The predefined operators (+, *, <, and so on) are not considered members. For more information, see Overloadable Operators (C# Programming Guide).

Indexers (C# Programming Guide)

Indexers enable an object to be indexed in a manner similar to arrays.

Constructors (C# Programming Guide)

Constructors are methods that are called when the object is first created. They are often used to initialize the data of an object.

Destructors (C# Programming Guide)

Destructors are used very rarely in C#. They are 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 must be released are handled appropriately.

Nested Types (C# Programming Guide)

Nested types are types declared within another type. Nested types are often used to describe objects that are used only by the types that contain them.

See Also

Reference

Classes (C# Programming Guide)

Methods (C# Programming Guide)

Constructors (C# Programming Guide)

Destructors (C# Programming Guide)

Properties (C# Programming Guide)

Fields (C# Programming Guide)

Indexers (C# Programming Guide)

Events (C# Programming Guide)

Nested Types (C# Programming Guide)

Operators (C# Programming Guide)

Overloadable Operators (C# Programming Guide)

Concepts

C# Programming Guide