存储串值作为同样地枚举常数 [英] Storing string values as constants in the same manner as Enum
本文介绍了存储串值作为同样地枚举常数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有一种方法,使字符串类型与转换嘉豪枚举的工作 - 在code不看pretty的。
有谁知道有什么办法能有这样的事情:
公共SOMESTRUCTURE SessionKeys:字符串
{
值1 =value1key
值2 =value2key
NAME =名
}
所以后来在我的code,我可以把它称作:
SessionKeys.value1
解决方案
这是关于最好的我想出。 (我还没有编制,所以语法可能会关闭。)
公共静态类SessionKeys
{
公共常量字符串值1 =值1;
公共常量字符串值2 =值2;
...
}
I know there is a way to make enum work for string types with conversions galore - the code doesn't look pretty.
Does anyone know of any way to have something like this:
public SOMESTRUCTURE SessionKeys : string
{
value1 = "value1key",
value2 = "value2key",
name = "name"
}
so later in my code I could refer to it as:
SessionKeys.value1
解决方案
This is about the best I've come up with. (I haven't compiled it, so the syntax may be off.)
public static class SessionKeys
{
public const string Value1 = "Value1";
public const string Value2 = "Value2";
...
}
这篇关于存储串值作为同样地枚举常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文