Re: Dynamically Creating Variables in C#




<ann.smithry@xxxxxxxxx> wrote in message
news:1153093771.742172.142960@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.


How would you know how to access them at compile time then?

If, say, size is a user defined input then how can you know if at runtime,
say, there will be a temp2341 or not? If you try and access it and size <
2341 then you have a compile time error... yet its at runtime.

You can make these variables at compile time if size you know how many you
want. Although it would be equivilent to manually making them.

As Leslie said, you can use arrays and this is effectively what you are
wanting to do anyways and actually makes much more sense.


.



Relevant Pages

  • Re: Dynamically Creating Variables
    ... ann wrote: ... I want my variables to be temp0, temp1, temp2, etc. ...
    (microsoft.public.dotnet.languages.csharp)
  • Dynamically Creating Variables
    ... Is there any way to dynamically creat variables? ... I want my variables to be temp0, temp1, temp2, etc. ...
    (microsoft.public.dotnet.languages.csharp)
  • Dynamically Creating Variables in C#
    ... Is there any way to dynamically creat variables? ... I want my variables to be temp0, temp1, temp2, etc. ...
    (comp.programming)