例如:
(1).SomeFunction().Equals("one") (2).SomeFunction().Equals("two")
在我正在使用的情况下,我真的只需要数字1-9,我应该只使用一个开关/选择案例吗?@H_403_4@
更新我也不需要本地化.@H_403_4@
Private Enum EnglishDigit As Integer zero one two three four five six seven eight nine End Enum (CType(someIntThatIsLessThanTen,EnglishDigit)).ToString()
枚举怎么样?
原文链接:https://www.f2er.com/vb/255344.htmlenum Number { One = 1,// default value for first enum element is 0,so we set = 1 here Two,Three,Four,Five,Six,Seven,Eight,Nine,}
然后你可以输入像…这样的东西@H_403_4@
((Number)1).ToString()
如果您需要本地化,则可以为每个枚举值添加DescriptionAttribute
.属性的Description属性将存储资源项的密钥的名称.@H_403_4@
enum Number { [Description("NumberName_1")] One = 1,so we set = 1 here [Description("NumberName_2")] Two,// and so on... }
以下函数将从属性中获取Description属性的值@H_403_4@
public static string GetDescription(object value) { DescriptionAttribute[] attributes = null; System.Reflection.FieldInfo fi = value.GetType().GetField(value.ToString()); if (fi != null) { attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute),false); } string description = null; if ((attributes != null) && (attributes.Length > 0)) { description = attributes[0].Description; } return description; }
GetDescription(((Number)1))
然后,您可以从资源文件中提取相关值,或者如果返回null则只调用.ToString().@H_403_4@
编辑@H_403_4@