this is a bit of a noob question and I'm not sure if it can be done but Ill ask anyway.
I have a string that I am using to invoke a method with reflection
At the moment I'm usingCode:Static string Rank1 = "contents"
But I would like to eliminate the mess of adding in all the if's for each level.Code:var kit = ""; If (playerLevel == 1) kit = Rank1;
I was thinking something like
Which gives me the string name, my question is;Code:var kit = ("Rank" + playerLevel.ToString())
Is there anyway to take that and have it read the contents of the string with the same name?
Solved Getting string contents by generating string name
Discussion in 'Rust Development' started by k1lly0u, Dec 2, 2015.
-
Calytic Community Admin Community Mod
Nope. C# is strongly-typed and does not have dynamic variables or "variable variables" like PHP.
You will have to use a dictionary.
Code:Dictionary<string, int> names = new Dictionary<string,int>(); for (int i = 0; i < 10; i++) { names.Add(String.Format("name{0}", i.ToString()), i); } var xx1 = names["name1"]; var xx2 = names["name2"]; var xx3 = names["name3"];
-
Thanks