M
Mark S.
As I understand it, C# doesn't offer dynamic variable names. Below is my
attempted workaround. Is what I'm doing possible?
FYI, I already read all the "why in the world do you need dynamic variabale
names" comments by other posters, if you are kind enough to post a reply
please either say it's impossible, or it is possible if I did x. TIA
using System;
namespace ConsoleForTesting
{
class test
{
public static string foo1 = "1";
public static string foo2 = "2";
public static string foo3 = "3";
public static string getFoo(int rowNumber)
{
switch (rowNumber)
{
case 1:
return foo1;
case 2:
return foo2;
case 3:
return foo3;
}
return "";
}
static void Main(string[] args)
{
Console.WriteLine(foo2);
// how can x be used to represent foo2?
// assume x can't be used later to update the foo2.
String x = getFoo(2);
x = "updated";
// foo returns 2, but I need it to return "updated"
Console.WriteLine(foo2);
Console.ReadLine();
}
}
}
attempted workaround. Is what I'm doing possible?
FYI, I already read all the "why in the world do you need dynamic variabale
names" comments by other posters, if you are kind enough to post a reply
please either say it's impossible, or it is possible if I did x. TIA
using System;
namespace ConsoleForTesting
{
class test
{
public static string foo1 = "1";
public static string foo2 = "2";
public static string foo3 = "3";
public static string getFoo(int rowNumber)
{
switch (rowNumber)
{
case 1:
return foo1;
case 2:
return foo2;
case 3:
return foo3;
}
return "";
}
static void Main(string[] args)
{
Console.WriteLine(foo2);
// how can x be used to represent foo2?
// assume x can't be used later to update the foo2.
String x = getFoo(2);
x = "updated";
// foo returns 2, but I need it to return "updated"
Console.WriteLine(foo2);
Console.ReadLine();
}
}
}