关于C#中查找Enum成员的问题
如何快速查找枚举 obj 并找出枚举 obj 包含/不包含另一个输入成员?
public enum myen
{
S1,
S2,
S3,
}
other member like s2 or s4.
intput s2 -> true; // included
input s4 -> false; // not include
How can I rapidly look up my enum obj and find out the enum obj include/not include another input member?
public enum myen
{
S1,
S2,
S3,
}
other member like s2 or s4.
intput s2 -> true; // included
input s4 -> false; // not include
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Enum.IsDefined 或根据内容使用 Enum.GetNames是你拥有的输入。
Enum.IsDefined or use Enum.GetNames based on what is the input that you have.
我建议编写您自己的基于泛型的
Enum.IsDefined()
版本,它会缓存结果而不是对值进行装箱和拆箱;这可能会导致您在问题中所说的“快速”查找。I recommend writing your own version of
Enum.IsDefined()
that's based on generics, and that caches results instead of boxing and unboxing the values; that can result in the "rapid" lookup you stated in your question.