c# - 如何为特定值设置内部枚举?

标签 c# enums access-modifiers

我想将 enum 作为 public,但其中一个 enum 值应该是 internal。这在 C# 中可能吗?

public enum Numbers
{
      One,
      Two,
      Three,
      internal Zero // I want zero as internal
}

最佳答案

我认为您可以使用以下代码实现此目的:

public static class Numbers
{
    public static readonly int One = 1;
    public static readonly int Two = 2;
    public static readonly int Three = 3;
    internal static readonly int Zero = 0;
}

此外,它可以像 enum 一样使用。

关于c# - 如何为特定值设置内部枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50578497/

相关文章:

swift - 枚举和闭包组合

java - 将类枚举传递给克隆是否克隆安全?

c# - PowerShell 字符串命令中的管道字符在 Csharp C# 代码中无法识别

c# - 如何对空枚举进行单元测试?

java - 访问修饰符在 JVM 内部如何工作?

c# - C# 中的访问修饰符

Java - 运行时反射设置值

c# - SharpZipLib - ZipException "System.ArgumentOutOfRangeException"- 为什么我会收到此异常?

c# - 如何判断 MemberInfo 是否表示覆盖

c# - Blazor - 私有(private)组件