1. 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
    Code:
    Static string Rank1 = "contents"
    At the moment I'm using
    Code:
    var kit = "";
    If (playerLevel == 1) kit = Rank1;
    But I would like to eliminate the mess of adding in all the if's for each level.
    I was thinking something like
    Code:
    var kit = ("Rank" + playerLevel.ToString())
    Which gives me the string name, my question is;
    Is there anyway to take that and have it read the contents of the string with the same name?
     
  2. Calytic

    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"];
     
  3. Thanks