C#可以访问没有完全限定名称的枚举

use*_*169 8 c# enums

我有一个C#enum类型,最终有很长的限定名.例如

DataSet1.ContactLogTypeValues.ReminderToFollowupOverdueInvoice.
Run Code Online (Sandbox Code Playgroud)

为了便于阅读,如果我能告诉某个特定的函数只使用名称的最后一部分,那会很好...

{
    using DataSet1.ContactLogTypeValues;
    ...
    logtype = ReminderToFollowupOverdueInvoice;
    ...
}
Run Code Online (Sandbox Code Playgroud)

是否有可能在C#中做这样的事情?

Nik*_*dze 5

您可以使用using指令来指定别名。它会存在于文件中的任何地方,而不是存在于一种特定的方法中。


jcs*_*ica 5

从C#6开始,您可以使用using static

using static DataSet1.ContactLogTypeValues;
...
logtype = ReminderToFollowupOverdueInvoice;
...
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参见https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/using-static