Link to home
Start Free TrialLog in
Avatar of paulpp
paulppFlag for United States of America

asked on

C# Calling data member using a concatenated string

Hello,

I asked this question earlier in Javascript, but now I can't get it to work in C#.  I am looking to do something like below:

currentPart = results[0]["orderPart" + i];

Open in new window


Results is an object of a class.  In this class there are 5 members named:
orderPart1
orderPart2
... orderPart5

I am looking to update these 5 members by using a for loop to iterate the last character of the data member name.  I have tried using the dot operator and other symbols.  I have checked C and C++ options also, with no success.

Any help is appreciated.  Thank you.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

You would need to use REFLECTION.  Is "orderPart1" just a public/private Member, or is it an actual Property?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paulpp

ASKER

Thank you both for the information - I will look it up and see if it solves my problem.

@Idle_Mind - orderPart1 is a public member.

Thank you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial