简体   繁体   English

用另一个字符串的名称来转录一个字符串调用它,这可能吗? 在 c# 关于统一

[英]to transcribe a string calling it with the name of another string, is it possible? in c# on unity

I have a string variable called "A" and the internal string is "a000_1" (the numbers of this string can change.) then I have other strings called: "a000_1", "a000_2", "a000_3" etc ... (with each a different text inside) I have to transcribe the variables a001 etc. calling them automatically with the string "A"我有一个名为“A”的字符串变量,内部字符串是“a000_1”(这个字符串的数字可以改变。)然后我有其他字符串叫做:“a000_1”、“a000_2”、“a000_3”等......(每个内部都有不同的文本)我必须转录变量 a001 等。用字符串“A”自动调用它们

so if the text inside the string "A" is, for example, "a000_7" it must transcribe the text inside the variable "a000_7"因此,如果字符串“A”中的文本是,例如,“a000_7”,它必须转录变量“a000_7”中的文本

ExampleText.SetText(A)

but obviously if I do that transcribes me "a000_7", if we want to go back to the example above, and not the text inside the variable a000_7但显然,如果我这样做会转录为“a000_7”,如果我们想回到上面的示例,而不是变量 a000_7 中的文本

I guess you could use a dictionary here:我想你可以在这里使用字典:

Dictionary<string, string> dict = new Dictionary<string, string> {
    ["a000_1"] = "test1",
    ["a000_2"] = "test2",
    ["a000_3"] = "test3",
    ["a000_4"] = "test4",
    ["a000_5"] = "test5",
    ["a000_6"] = "test6",
    ["a000_7"] = "test7",
};
String A = "a000_7";
Console.WriteLine(dict[A]);

In this case, you can access one of the strings by name by using A as the key to the dict在这种情况下,您可以使用 A 作为 dict 的键,按名称访问其中一个字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM