问题
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;
}
}
}
}
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?
回答1:
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.
来源:https://stackoverflow.com/questions/45223740/why-is-it-not-possible-to-use-using-static-feature-with-private-enum-is-there