Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

C# Calling data member using a concatenated string


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:
... 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.
  • 3
2 Solutions
Mike TomlinsonMiddle School Assistant TeacherCommented:
You would need to use REFLECTION.  Is "orderPart1" just a public/private Member, or is it an actual Property?
paulppAuthor Commented:
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.
Mike TomlinsonMiddle School Assistant TeacherCommented:
It will be very similar to my example, then, except you'd call GetValue() instead of SetValue():

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now