Re: Dynamically Creating Variables in C#
- From: "Leslie Sanford" <jabberdabber@xxxxxxxxxxxxxxxxx>
- Date: Sun, 16 Jul 2006 19:19:36 -0500
<ann.smithry@xxxxxxxxx> 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.
This isn't possible, but you can use an array instead:
int size = 10;
string[] temp = new string[size];
for(int i = 0; i < temp.Length; i++)
{
temp[i] = (i * 3).ToString();
}
Then you can refer to the elements in the array as temp[0], temp[1],
temp[2], etc... on up to one less than the length of the array.
.
- References:
- Dynamically Creating Variables in C#
- From: ann . smithry
- Dynamically Creating Variables in C#
- Prev by Date: Re: C is too old? opinions?
- Next by Date: Extremely easy question about Time to check table look-ups
- Previous by thread: Dynamically Creating Variables in C#
- Next by thread: Re: Dynamically Creating Variables in C#
- Index(es):
Relevant Pages
|