paulpp
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:
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.
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];
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.
You would need to use REFLECTION. Is "orderPart1" just a public/private Member, or is it an actual Property?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
@Idle_Mind - orderPart1 is a public member.
Thank you.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.