gpt4 book ai didi

c# - 是否可以搜索枚举类型的值列表以查看是否存在 int?

转载 作者:行者123 更新时间:2023-11-30 19:20:41 24 4
gpt4 key购买 nike

假设我有一个枚举

public myEnum
{
value1, value2

}

如果我有一个整数,我可以查看它是否存在于 myEnum 中吗?

最佳答案

使用 Enum.IsDefined()。完整的定义是

public static bool IsDefined(
Type enumType,
Object value
)

示例用法:

public enum MyEnum { A = 1, B = 2 };

Enum.IsDefined(typeof(MyEnum), 1) --> true
Enum.IsDefined(typeof(MyEnum), 3) --> false

您可以找到更多信息on this msdn page .

关于c# - 是否可以搜索枚举类型的值列表以查看是否存在 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5480761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com