merging strings to access variable

  • Thread starter Thread starter Barbara
  • Start date Start date
B

Barbara

Is it possible in C# to merge two strings to access variable?
(Like in JScript: document('variable'+200).style...)

What I am trying to do is:
I have a class Structure.cs
I would like to create several Structure-s, fill their elements with data,
but in a way that
I can choose starting number (sometimes I need Structure[201],[202],
sometimes [301,302])
 
Barbara said:
Is it possible in C# to merge two strings to access variable?

The answer to questions like this is almost always to use either an
array or a hashtable.
(Like in JScript: document('variable'+200).style...)

What I am trying to do is:
I have a class Structure.cs
I would like to create several Structure-s, fill their elements with data,
but in a way that
I can choose starting number (sometimes I need Structure[201],[202],
sometimes [301,302])

Well, you *can* create arrays with non-zero lower bounds, but it's
rarely a good idea, IMO. Could you give us more information about why
you need this?
 
I need a way of filling a class variables with data depending on users
choice.
There can be any number of classes used at once and I need to distinguish
between them.
Class with its variables is used to construct a form (modify it by adding
different controls).
 
Barbara said:
I need a way of filling a class variables with data depending on users
choice.
There can be any number of classes used at once and I need to distinguish
between them.
Class with its variables is used to construct a form (modify it by adding
different controls).

Well, you could use reflection - but if you're really just going to
access them by number, using an array would be the obvious answer.
 
Back
Top