For example, PHP code:
$test = "hello";
${$test} = $test;
echo $hello; // return hello
How to do this in C#? Thanks in advance.
UPD: Dynamic variable in C#? - here is an answer.
For example, PHP code:
$test = "hello";
${$test} = $test;
echo $hello; // return hello
How to do this in C#? Thanks in advance.
UPD: Dynamic variable in C#? - here is an answer.
This isn't supported in C#. You could use an ExpandoObject and set a member on it, but it's not quite the same as the PHP code. You'll still need to refer to the ExpandoObject by a variable name.
dynamic myObject = new ExpandoObject();
string test = "Hello";
((IDictionary<string, object>)myObject).Add(test, test);
Console.WriteLine(myObject.Hello);
Nonetheless, this doesn't help with code clarity. If all you want to do is map a name to a value you can use a Dictionary, which is really what ExpandoObject uses internally, as demonstrated by the cast in the code above.
$test = 'foo', then${$test}accesses$foo.