0

I'm trying to create a method that names a variable based on a specific set of other variables. For example, I want to create series of Lists (i.e., List1, List2, List3) by named according to two variables. For example:

string l = "List"
int += 1

Such that as I cycled through the code using a foreach loop it would name each List consecutively. Any ideas? I've only gotten this much "correct" so far and its not much:

public static string[] ListRenamer(List<string> list, int num)
{
    string x = list.ToString();
    string y = num.ToString();
    string[] z = new string[1];

    return z;
}
4

1 回答 1

4

我会Dictionary<string,List<string>>在这里考虑一个而不是单独的列表。然后,您可以根据约定命名键,并且可以在运行时动态完成。由于 c# 是一种静态语言,因此无法在运行时重命名 c# 变量

于 2013-09-20T04:23:35.633 回答