By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,333 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,333 IT Pros & Developers. It's quick & easy.

Variable interpolation

P: n/a
Hi there..

I am wondering if it is possible to interpolate the value of a
variable to reference a variable to gain its value.

For example:-

if I have a series of variables:-

var01
var02
var03
var04

(I would arrange them into an array, but they are being generated via
form input)

Let's say I wanted to access these in order using a loop, I would
quite like to use a counter variable that I can increment each time;
counterVar.

Ideally I would like to be able to access the variables using
something to the effect of:-

Console.Writeline(var + counterVar);

counterVar++

Console.Writeline(var + counterVar);

using PHP I would achieve this using $var{$counterVar}
(to give another example).

I hope someone can shed some light onto whether or not this is
possible.

Thanks in advance

Jason Dunbar
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Jason,

That is easy using an interpreted language, it's as easy using a compiled
one.
With that in mind you have to find another solution, one could be using a
hashtable, you can use the "name" of the variable as the key.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jason Dunbar" <jason__D0T__dunbar__AT__intechnology__D0T__co__D0 Tuk> wrote
in message news:kv********************************@4ax.com...
Hi there..

I am wondering if it is possible to interpolate the value of a
variable to reference a variable to gain its value.

For example:-

if I have a series of variables:-

var01
var02
var03
var04

(I would arrange them into an array, but they are being generated via
form input)

Let's say I wanted to access these in order using a loop, I would
quite like to use a counter variable that I can increment each time;
counterVar.

Ideally I would like to be able to access the variables using
something to the effect of:-

Console.Writeline(var + counterVar);

counterVar++

Console.Writeline(var + counterVar);

using PHP I would achieve this using $var{$counterVar}
(to give another example).

I hope someone can shed some light onto whether or not this is
possible.

Thanks in advance

Jason Dunbar

Nov 16 '05 #2

P: n/a
Jason,

The best way to do this would be to store the values in a Hashtable (a
Dictionary<> in .NET 2.0, for strongly typed lookup tables) and then key it
on a string that you can generate.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jason Dunbar" <jason__D0T__dunbar__AT__intechnology__D0T__co__D0 Tuk> wrote
in message news:kv********************************@4ax.com...
Hi there..

I am wondering if it is possible to interpolate the value of a
variable to reference a variable to gain its value.

For example:-

if I have a series of variables:-

var01
var02
var03
var04

(I would arrange them into an array, but they are being generated via
form input)

Let's say I wanted to access these in order using a loop, I would
quite like to use a counter variable that I can increment each time;
counterVar.

Ideally I would like to be able to access the variables using
something to the effect of:-

Console.Writeline(var + counterVar);

counterVar++

Console.Writeline(var + counterVar);

using PHP I would achieve this using $var{$counterVar}
(to give another example).

I hope someone can shed some light onto whether or not this is
possible.

Thanks in advance

Jason Dunbar

Nov 16 '05 #3

P: n/a
Thanks for the suggestions folks.

On Mon, 27 Sep 2004 15:18:14 +0100, Jason Dunbar
<jason__D0T__dunbar__AT__intechnology__D0T__co__D0 Tuk> wrote:
Hi there..

I am wondering if it is possible to interpolate the value of a
variable to reference a variable to gain its value.

For example:-

if I have a series of variables:-

var01
var02
var03
var04

(I would arrange them into an array, but they are being generated via
form input)

Let's say I wanted to access these in order using a loop, I would
quite like to use a counter variable that I can increment each time;
counterVar.

Ideally I would like to be able to access the variables using
something to the effect of:-

Console.Writeline(var + counterVar);

counterVar++

Console.Writeline(var + counterVar);

using PHP I would achieve this using $var{$counterVar}
(to give another example).

I hope someone can shed some light onto whether or not this is
possible.

Thanks in advance

Jason Dunbar


Nov 16 '05 #4

P: n/a
"Jason Dunbar" <jason__D0T__dunbar__AT__intechnology__D0T__co__D0 Tuk>
wrote@
if I have a series of variables:-
var01, var02, var03, var04
(I would arrange them into an array, but they are
being generated via form input)


Surely the sane thing to do here is to convert them into an array.

string[] s = new string[4];

for (int i = 1; i <= 4; i++)
{
s[i] = ValueFromForm("var0" + i);
}

P.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.