Reputation: 778
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;
}
Upvotes: 0
Views: 80
Reputation: 39268
I would consider a Dictionary<string,List<string>>
instead of separate lists here.
You can then name the keys according to your convention, and it can be done dynamically at runtime.
It is not possible to rename c# variables at runtime since c# is a static language
Upvotes: 4