元編程參考文件

列舉操作

20 個節點

本頁內容 20

新增標誌

函數

Switches on the bits of Flag in Value; for a flag enum, adds that option. Options already on stay on.

簽名
新增標誌(值: TEnum, 標誌: TEnum) -> TEnum
TEnum AddFlag(TEnum value, TEnum flag)

參數

名稱型別預設值說明
值TEnum—The value to start from; a value below zero throws System.OverflowException.
標誌TEnum—The flag or flags to add; a value below zero throws System.OverflowException.

返回

ResultTEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

格式化

函數

Writes an enum value as text in a chosen style: its name, its number in decimal or hexadecimal, or its flags spelled out by name.

簽名
格式化(值: TEnum, 格式: 文字) -> 文字
string Format(TEnum value, string format)

參數

名稱型別預設值說明
值TEnum—The value to write.
格式文字—"G" for the name (or the number when it has none), "D" for decimal, "X" for hexadecimal, "F" for a comma-separated list of flag names; letter case does not matter. Null, empty or white-space throws System.ArgumentException, and any other format throws System.FormatException.

返回

結果文字
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

由數值取列舉值

函數

Turns a number into the enum value with that number, for example a value read from a file or a database column.

簽名
由數值取列舉值(值: 任意) -> TEnum
TEnum FromValue(object value)

參數

名稱型別預設值說明
值任意—The number to convert. Null throws System.ArgumentNullException; a value that cannot be converted throws System.InvalidCastException or System.FormatException; a number outside the underlying type's range throws System.OverflowException.

返回

ResultTEnum

備註

The number is first converted to the enum's underlying integer type using invariant culture: text holding a number works, and a fractional number is rounded to the nearest whole number (halves to even). The result is not checked against the declared constants; use EnumRoutines.TryFromDefinedValue for that.

所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

取得列舉值

函數

Every value of an enum type chosen at run time, for when you only have the type as a value rather than as the node's type argument.

簽名
取得列舉值(列舉型別: Type) -> 陣列
Array GetEnumValues(Type enumType)

參數

名稱型別預設值說明
列舉型別Type—The enum type to list; null throws System.ArgumentNullException and a type that is not an enum throws System.ArgumentException.

返回

結果陣列
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

取得名稱

函數

The declared name of Value, or empty text when no constant has that exact value (for example a combination of flags without a name of its own).

簽名
取得名稱(值: TEnum) -> 文字
string GetName(TEnum value)

參數

名稱型別預設值說明
值TEnum—The value to name.

返回

結果文字
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

取得所有名稱

函數

The names of every constant the enum declares, for example to fill a drop-down list.

簽名
取得所有名稱() -> 文字陣列
string[] GetNames()

返回

結果文字陣列
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

取得基礎型別

函數

The integer type an enum stores its values in, which is System.Int32 unless the enum declares otherwise.

簽名
取得基礎型別() -> Type
Type GetUnderlyingType()

返回

結果Type
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

取得值列表

函數

Every value the enum declares, as a read-only list; the same values in the same order as EnumRoutines.GetValues.

簽名
取得值列表() -> IReadOnlyList<TEnum>
IReadOnlyList<TEnum> GetValueList()

返回

結果IReadOnlyList<TEnum>
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

取得所有值

函數

Every value the enum declares, for example to go through all the choices one by one.

簽名
取得所有值() -> TEnum 陣列
TEnum[] GetValues()

返回

結果TEnum 陣列
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

包含標誌

函數

Whether every bit set in Flag is also set in Value; for a flag enum, whether the value includes that option (or all of several combined options).

簽名
包含標誌(值: TEnum, 標誌: TEnum) -> 真否
bool HasFlag(TEnum value, TEnum flag)

參數

名稱型別預設值說明
值TEnum—The combined value to test; a value below zero throws System.OverflowException.
標誌TEnum—The flag or flags to look for; a zero flag is always present. A value below zero throws System.OverflowException.

返回

結果真否
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

是否已定義

函數

過載 1/2

簽名
是否已定義(值: TEnum) -> 真否
bool IsDefined(TEnum value)

Whether Value is exactly one of the enum's named constants; use it to reject numbers that were cast or converted into the enum without matching any choice.

參數

名稱型別預設值說明
值TEnum—The value to check.

返回

結果真否

備註

A combination of flags counts as defined only when the enum gives that combination its own name.

過載 2/2

簽名
是否已定義(名稱: 文字) -> 真否
bool IsDefined(string name)

Whether the enum declares a constant called Name, matched exactly and case-sensitively.

參數

名稱型別預設值說明
名稱文字—The name to look for; null, empty or white-space text answers false. A number in text form is not a name and answers false.

返回

結果真否
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

是否為零

函數

Whether Value has no bits set at all; for a flag enum, whether no option is chosen.

簽名
是否為零(值: TEnum) -> 真否
bool IsZero(TEnum value)

參數

名稱型別預設值說明
值TEnum—The value to test; a value below zero throws System.OverflowException.

返回

結果真否
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

解析列舉

函數

Turns text into an enum value, throwing when it cannot; use EnumRoutines.TryParse when the text may be bad.

簽名
解析列舉(文字: 文字, 忽略大小寫: 真否) -> TEnum
TEnum Parse(string text, bool ignoreCase = true)

參數

名稱型別預設值說明
文字文字—The text to read. Null throws System.ArgumentNullException; empty, white-space or unrecognised text throws System.ArgumentException; a number too large for the enum's underlying type throws System.OverflowException.
忽略大小寫真否TrueWhen true (the default), names match regardless of letter case.

返回

ResultTEnum

備註

The text may be a constant's name, a comma-separated list of names (combined as flags), or a number; a number is accepted even when no constant has that value, so check the result with EnumRoutines.IsDefined or use EnumRoutines.TryParseDefined if that matters.

所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

移除標誌

函數

Switches off the bits of Flag in Value; for a flag enum, removes that option. Options already off stay off.

簽名
移除標誌(值: TEnum, 標誌: TEnum) -> TEnum
TEnum RemoveFlag(TEnum value, TEnum flag)

參數

名稱型別預設值說明
值TEnum—The value to start from; a value below zero throws System.OverflowException.
標誌TEnum—The flag or flags to remove; a value below zero throws System.OverflowException.

返回

ResultTEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

切換標誌

函數

Flips the bits of Flag in Value: options that were on go off and options that were off come on.

簽名
切換標誌(值: TEnum, 標誌: TEnum) -> TEnum
TEnum ToggleFlag(TEnum value, TEnum flag)

參數

名稱型別預設值說明
值TEnum—The value to start from; a value below zero throws System.OverflowException.
標誌TEnum—The flag or flags to flip; a value below zero throws System.OverflowException.

返回

ResultTEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

嘗試由已定義的數值取列舉值

函數

Turns a number into the enum value with that number only if it is one of the enum's named constants; answers false for null, unconvertible or undeclared values instead of throwing.

簽名
嘗試由已定義的數值取列舉值(值: 任意) -> (結果: 真否, 結果: TEnum)
bool TryFromDefinedValue(object value, out TEnum result)

參數

名稱型別預設值說明
值任意—The number to convert; may be null.

返回

結果真否
結果TEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

嘗試由數值取列舉值

函數

Turns a number into the enum value with that number like EnumRoutines.FromValue, but answers false instead of throwing when the value is null or cannot be converted.

簽名
嘗試由數值取列舉值(值: 任意) -> (結果: 真否, 結果: TEnum)
bool TryFromValue(object value, out TEnum result)

參數

名稱型別預設值說明
值任意—The number to convert; may be null.

返回

結果真否
結果TEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

嘗試取得名稱

函數

The declared name of Value, or null when no constant has that exact value; unlike EnumRoutines.GetName, this lets you tell "no name" apart from a name.

簽名
嘗試取得名稱(值: TEnum) -> 文字
string TryGetName(TEnum value)

參數

名稱型別預設值說明
值TEnum—The value to name.

返回

結果文字
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

嘗試解析列舉

函數

Turns text into an enum value without throwing, telling you whether it succeeded; it accepts the same text as EnumRoutines.Parse, including numbers that match no named constant.

簽名
嘗試解析列舉 -> (結果: 真否, 值: TEnum)
    文字: 文字
    忽略大小寫: 真否
bool TryParse(
    string text,
    out TEnum value,
    bool ignoreCase = true)

參數

名稱型別預設值說明
文字文字—The text to read; null, empty or unrecognised text answers false.
忽略大小寫真否TrueWhen true (the default), names match regardless of letter case.

返回

結果真否
值TEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫

嘗試解析已定義的列舉

函數

Turns text into an enum value only if the result is one of the enum's named constants, so stray numbers and unnamed flag combinations are rejected; use it for validating user input.

簽名
嘗試解析已定義的列舉 -> (結果: 真否, 值: TEnum)
    文字: 文字
    忽略大小寫: 真否
bool TryParseDefined(
    string text,
    out TEnum value,
    bool ignoreCase = true)

參數

名稱型別預設值說明
文字文字—The text to read; null, empty or unrecognised text answers false.
忽略大小寫真否TrueWhen true (the default), names match regardless of letter case.

返回

結果真否
值TEnum
所屬發行版
元編程(教育版)元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
列舉操作
所屬包
標準庫