Robert Murphy

Robert Murphy

  • 1.6k
  • 7
  • 251

Want to reference a class by an index

Jan 9 2024 9:24 PM

I have a class and a reference to the class by a list:

       public class class1
       {
           public string ADR_HOME;
           public string ADR_PREF_HOME;
           public string TEL_WORK;
           public string TEL_WORK_PREF;
           public string VERSION;
       }
       List<class1> lst1 = new List<class1>();
       
I can reference an element by
    string s1 = lst1[anindex].ADR_HOME;  // I do not want to hard code the element name
    
I want to be able to reference an element by an index
    string s1 = lst1[anIndex].(1) // Want to return the data in ADR_HOME

I also want to be able to get the name that is associated with     
    string elementName = lst1[anIndex].(1)  // want to return "ADR_HOME"
 


Answers (7)