0

Say I have a List called this_list. If I make a string that says "this_list", how can I turn that string into the actual variable? It should do the opposite of what nameof would do.

List<string> this_list = new List<string> { "wow","amazing" };
string str = "this_list";
// str to this_list somehow

1 Answers1

0

If this_list is a local variable (like in your example), you can't. Local variable names are lost during compilation.

If this_list is a field or property, you can use Reflection.

Heinzi
  • 167,459
  • 57
  • 363
  • 519