Is it possible to use a dynamic variable (not sure about naming) in C#?
In PHP, I can do
$var_1 = "2";
$var_2 = "this is variable 2";
$test = ${"var_".$var_1};
echo $test;
output: this is variable 2;
Can we do this in C#?
Dynamic Variable Overview The distinguishing characteristic of a dynamic variable is that its value can change while the application runs. For example, your application might maintain a threshold value that is compared to a field value in each tuple processed.
A dynamic variable is a variable you can declare for a StreamBase module that can thereafter be referenced by name in expressions in operators and adapters in that module. In the declaration, you can link each dynamic variable to an input or output stream in the containing module.
In the static memory allocation, variables get allocated permanently, till the program executes or function call finishes. In the Dynamic memory allocation, variables get allocated only if your program unit gets active. Static Memory Allocation is done before program execution.
In C, variables are always statically (or lexically) scoped i.e., binding of a variable can be determined by program text and is independent of the run-time function call stack. For example, output for the below program is 0, i.e., the value returned by f() is not dependent on who is calling it.
In C#, you use dictionaries to associate values with strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With