Re: Dynamically Creating Variables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



ann wrote:

Is there any way to dynamically creat variables?

In other words, I want to be able to do something like that:

for(int i=0; i<size; i++){

string temp+i = i*3;

}

I want my variables to be temp0, temp1, temp2, etc.

Hi Ann,

Why not use an array?

///
string[] temp = new string[size];

for ( int i = 0; i < size; i++ )
temp[i] = i * 3;
///

Then you can access each element with temp[0], temp[1] ... up to
temp[size-1].

--
Hope this helps,
Tom Spink

Google first, ask later.
.



Relevant Pages