Skip to content

Accessing object within list

Craig Davis

Asked Jul 23, 2015, 11:07 AM EDT2 answers
Share
LinkedInX
I have a parent object Z which contains a list of child objects.  I would like to access the properties of the child objects within the list.
 
I wrote code to access the first object in the list.  The code compiles correctly but returns a (object reference not set to instance of an object) error when I run the application.
 
Here is part of the code:
 
Code
zparentobject= new Zclass();
childclass zchildobject = new childclass();
zchildobject=zparentobject.listz[0];  * source of error*
 
Help?

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Ashwani Chaudhary
    0
    Hello Craig Devis please provide the complete code because it make me understand that are you using inheritance here ....if it is so then i will help you but need completed hierarchy of code ...
     
     
    Thanks
    0
  • 0
    Thanks, I realize my mistake. I called the code before I initialized the object.
    0