C# Calling data member using a concatenated string

Posted on 2012-09-12
Last Modified: 2012-09-13

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.
Question by:paulpp
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    You would need to use REFLECTION.  Is "orderPart1" just a public/private Member, or is it an actual Property?
    LVL 85

    Accepted Solution

    LVL 2

    Author Comment

    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.
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    It will be very similar to my example, then, except you'd call GetValue() instead of SetValue():

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now