我不知道怎么命名。
我的类(class)看起来像这样:
class exampleClass
{
string 1 = "Sth1";
string 2 = "Sth2";
string 3 = "Sth3";
int tmp;
}
我想在二等舱分配字段:
obj = new exampleClass();
obj.tmp = 3;
然后在第三节课中调出这个 tmp 字段:
if(obj.tmp == 3) show me string number 3 -> "Sth3".
总而言之。我不知道如何将此 tmp 与字符串相关联。我希望它是枚举类型或其他类型。
请您参考如下方法:
恕我直言,字典应该适合您的需要
Dictionary<int, string> myDict = new Dictionary<int, string>();
myDict.Add(1, "Sth1");
myDict.Add(2, "Sth2");
myDict.Add(3, "Sth3");
string Result = myDict[3]; //Sth3
