C#可以访问没有完全限定名称的枚举
我有一个C#枚举类型,最终有很长的限定名。 例如
DataSet1.ContactLogTypeValues.ReminderToFollowupOverdueInvoice.
为了便于阅读,如果我能告诉某个特定的函数只使用名称的最后一部分,那会很好…
{ using DataSet1.ContactLogTypeValues; ... logtype = ReminderToFollowupOverdueInvoice; ... }
是否有可能在C#中做这样的事情?
您可以使用using
指令指定别名。 它将存在于文件的任何位置,但不是在一个特定的方法中。
我意识到这可能不是你想象的解决方案,但它确实允许你编写你要求的代码。
enum ContactLogTypeValues { ReminderToFollowupOverdueInvoice, AnotherValue1, AnotherValue2, AnotherValue3 }; static ContactLogTypeValues ReminderToFollowupOverdueInvoice = ContactLogTypeValues.ReminderToFollowupOverdueInvoice; static ContactLogTypeValues AnotherValue1 = ContactLogTypeValues.AnotherValue1; static ContactLogTypeValues AnotherValue2 = ContactLogTypeValues.AnotherValue2; static ContactLogTypeValues AnotherValue3 = ContactLogTypeValues.AnotherValue3; static void Main(string[] args) { var a = ReminderToFollowupOverdueInvoice; }
从C#6开始,您可以使用using static
:
using static DataSet1.ContactLogTypeValues; ... logtype = ReminderToFollowupOverdueInvoice; ...
有关详细信息,请参阅https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-static 。
- 无法在System.Int32和System.String上执行“Like”操作。 DataGridView搜索和过滤
- 加载其他语言的资源
- 如何在C#中列出来自Google Drive API V3的1000多条记录
- 在Listbox中处理WPF中的图像(内存泄漏)
- C#为什么定时器频率非常低?
- 如果我等待我正在执行ReadAsStringAsync()的响应,我应该等待ReadAsStringAsync()吗?
- 打开oracle连接时,连接对象为null
- 是否有一个模拟Facebook“链接检测”的库?
- 需要将Asp.Net Identity(RTM)用户ID从nvarchar(128)更改为uniqueidentifier