为什么不能使用“使用静态"的功能,带有私人枚举的功能?有没有其他选择? [英] Why is it not possible to use "Using static" feature with private enum? Is there any alternative?

查看:48
本文介绍了为什么不能使用“使用静态"的功能,带有私人枚举的功能?有没有其他选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此类中使用私有枚举.我想使用C#6的使用静态"功能,如下所示:

I have this class where I use a private enum. I would like to use C# 6 "Using static" feature, like the following:

using static ConsoleForSimpleTests.Foo.MyEnum;

namespace ConsoleForSimpleTests
{
    public class Foo
    {
        private enum MyEnum { I, DonT, Want, This, To, Be, Public }

        private MyEnum value;

        public void SomeMethod()
        {
            switch (value)
            {
                    case I:
                    case DonT:
                    case Want:
                    case This:
                    case To:
                    case Be:
                    case Public:
                        break;
            }
        }
    }
}

注意:这不能编译,我理解为什么,这是由于MyEnum的保护级别所致.如果我将访问修饰符更改为内部修饰符或公共修饰符,则可以使用.我想知道的是,这根本不可能吗?如果可以,为什么呢?

NOTE: This does not compile and I understand why, it is due to the protection level for MyEnum. If I change the access modifier to either internal or public it works. What I wonder is if this is simply not possible and, if so, why is this not possible?

推荐答案

如果可能的话,并且在同一文件中还有其他一些类,则从该类中将看不到导入的符号.

If that were possible, and you had some other class in the same file, the symbols that you imported wouldn't be visible from that class.

那会令人困惑;这可能就是为什么它不起作用的原因.

That would be confusing; this is probably why that doesn't work.

这篇关于为什么不能使用“使用静态"的功能,带有私人枚举的功能?有没有其他选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆