列舉操作
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. |
返回
| Result | TEnum |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列舉操作
- 所屬包
- 標準庫
格式化
函數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. |
返回
| Result | TEnum |
備註
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. |
| 忽略大小寫 | 真否 | True | When true (the default), names match regardless of letter case. |
返回
| Result | TEnum |
備註
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. |
返回
| Result | TEnum |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列舉操作
- 所屬包
- 標準庫
切換標誌
函數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. |
返回
| Result | TEnum |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列舉操作
- 所屬包
- 標準庫
嘗試由已定義的數值取列舉值
函數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. |
| 忽略大小寫 | 真否 | True | When 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. |
| 忽略大小寫 | 真否 | True | When true (the default), names match regardless of letter case. |
返回
| 結果 | 真否 |
| 值 | TEnum |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列舉操作
- 所屬包
- 標準庫