成員Members

本節描述 F# 物件類型的成員。This section describes members of F# object types.

備註Remarks

「成員」是作為類型定義的一部分且以 member 關鍵字宣告的功能。Members are features that are part of a type definition and are declared with the member keyword. F# 物件類型 (例如記錄、類別、差別聯集、介面和結構) 支援成員。F# object types such as records, classes, discriminated unions, interfaces, and structures support members. 如需詳細資訊,請參閱記錄類別差別聯集介面結構For more information, see Records, Classes, Discriminated Unions, Interfaces, and Structures.

成員一般構成類型的公用介面,因此除非另外指定,否則成員為公用。Members typically make up the public interface for a type, which is why they are public unless otherwise specified. 成員也可以宣告為私用或內用。Members can also be declared private or internal. 如需詳細資訊,請參閱存取控制For more information, see Access Control. 類型的簽章也可以用來公開或不公開類型的特定成員。Signatures for types can also be used to expose or not expose certain members of a type. 如需詳細資訊,請參閱簽章For more information, see Signatures.

只與類別搭配使用的私用欄位和 do 繫結,並不是真正的成員,因為它們永遠不是類型之公用介面的一部分,也不是以 member 關鍵字宣告,但本節中也會加以描述。Private fields and do bindings, which are used only with classes, are not true members, because they are never part of the public interface of a type and are not declared with the member keyword, but they are described in this section also.

主題Topic 描述Description
類別中的 let 繫結let Bindings in Classes 描述類別中私用欄位和函式的定義。Describes the definition of private fields and functions in classes.
類別中的 do 繫結do Bindings in Classes 描述物件初始設定程式碼的規格。Describes the specification of object initialization code.
屬性Properties 描述類別和其他類型中的屬性成員。Describes property members in classes and other types.
索引屬性Indexed Properties 描述類別和其他類型中的類似陣列屬性。Describes array-like properties in classes and other types.
方法Methods 描述作為類型成員的函式。Describes functions that are members of a type.
建構函式Constructors 描述初始化型別物件的特殊函式。Describes special functions that initialize objects of a type.
運算子多載Operator Overloading 描述型別之自訂運算子的定義。Describes the definition of customized operators for types.
事件Events 描述 F# 中的事件定義和事件處理支援。Describes the definition of events and event handling support in F#.
明確欄位:val 關鍵字Explicit Fields: The val Keyword 描述類型中未初始化欄位的定義。Describes the definition of uninitialized fields in a type.