枚举操作
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 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 枚举操作
- 所属包
- 标准库