枚举器特殊字符问题 [英] Enumerator special characters problem
本文介绍了枚举器特殊字符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我在为某些特殊字符创建枚举器时遇到问题...
因此,我该如何实现以下目标(如果可能的话):
Hello, I have a problem creating an enumerator for some special characters...
So how can I achive the following(if its possible of course):
public enum MyEnumerator
{
InboundDocument = ->,
OutbountDocument = <-,
MyOwnDocument = v
}
感谢您的回答...
Thank you for your answer...
推荐答案
这不是枚举的工作原理.枚举可以将整数值映射到命名常量(即标识符),因此必须符合以下语法规则: ^ ].另一方面,值必须是整数类型,请参见: http://msdn.microsoft.com/en-us/library/sbbt4032(v=vs.80).aspx [ http://stackoverflow.com/questions/3916914/c-sharp -using-numbers-in-enum [
That is not how enum works. Enum can map an integral value to named constants, that are identifiers, thus have to conform to following syntax rules: http://msdn.microsoft.com/en-us/library/aa664670(v=vs.71).aspx[^]. On the other hand, values has to be integral type, see: http://msdn.microsoft.com/en-us/library/sbbt4032(v=vs.80).aspx[^]
You can however add attributes, and read them with reflection. Look here: http://stackoverflow.com/questions/3916914/c-sharp-using-numbers-in-an-enum[^]
尝试显示名称或描述枚举属性
http://msdn.microsoft.com/en-us/library/system.componentmodel. displaynameattribute.aspx [ ^ ]
Tried Display name OR Description enum attribute
http://msdn.microsoft.com/en-us/library/system.componentmodel.displaynameattribute.aspx[^]
我认为这可能有效
I think this might work
public enum MyEnumerator
{
[Description("->")]
InboundDocument = 0,
[Description("<-")]
OutbountDocument = 1,
[Description("V")]
MyOwnDocument = 2
}
谢谢...
Thanks...
这篇关于枚举器特殊字符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文