Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic variable in C#?

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#?

like image 312
Moon Avatar asked Aug 15 '09 21:08

Moon


People also ask

What is a dynamic variable example?

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.

What is variable dynamic?

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.

What is difference between static and dynamic variable?

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.

Are variables in C static or dynamic?

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.


1 Answers

In C#, you use dictionaries to associate values with strings.

like image 121
Martin v. Löwis Avatar answered Sep 19 '22 09:09

Martin v. Löwis