Access class members

In the code below, I want to access nth item of a list of class cPropertyValues, and return member variable that is represented by propertyName. I can do this by a simple string check on each member. But there are 50 members in cPropertyValues class. So is there a better way to access class members without performing individual comparison?

1
2
3
4
5
6
7
public string getPropertyValueByName(string propertyName)
        {
            List<cPropertyValues> list = GlobalClass.get_mPropertyValuesList;

            return (list[GlobalClass.itemIndex]).propertyName; //this won't work, since propertyName is not a member of cPropertyValues.

        }


Thanks!
Last edited on
What you're trying to do; and what your code is doing are very different.

I want to access the nth item of a list of class cPropertyValues


1
2
List<cPropertyValues] list = // etc;
cPropertyValues object = list[n];


I want to return member variable presented by propertyName


return object.getPropertyValue(propertyName);

This means you need to implement a method called getPropertyValue().



Last edited on
Thanks, got that working.
Topic archived. No new replies allowed.