Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

Here we go again! structure array within a structure not initializing...

I have a structure array within a structure.  I can't instantiate the inner array.  The code I am using to instantiate the two structures is as follows (it's in the method that uses the arrays):

            pricingData pD = new pricingData();
            pD.venueBookInfo[100] = new bookInfoByVenue();

The run-time error I'm getting is:

Object reference not set to an instance of an object. (referring to venueBookInfo which is null)


Is there another way of accomplishing what I want to do?  (I've spent 2 days on this, and I need to either get it running or find another way of doing it).
public struct pricingData  //  structure to hold the data obtained on a book
        {
            public string ISBN
            {
                set { ISBN = value; }
                get { return ISBN; }
            }
            public decimal listPrice
            {
                set { listPrice = value; }
                get { return listPrice; }
            }
            public bookInfoByVenue[] venueBookInfo;
        }
 
        public struct bookInfoByVenue
        {
            public string venueName
            {
                set { venueName = value; }
                get { return venueName; }
            }
            public bool newBook
            {
                set { newBook = value; }
                get { return newBook; }
            }
            public decimal price
            {
                set { price = value; }
                get { return price; }
            }
        }

Open in new window

0
rmmarsh
Asked:
rmmarsh
  • 4
  • 2
1 Solution
 
Jaime OlivaresCommented:
it should be:
pD.venueBookInfo= new bookInfoByVenue[100] ;
0
 
rmmarshAuthor Commented:
Damn!  you are good Jaime... thanks so much... I really appreciate it...  I knew there had to be a way to do this...

R
0
 
rmmarshAuthor Commented:
One more question:  how do I make the struct array visible outside of the class?  I have instantiated the class (obviously), and can see the objects in the struct, but can't see the objects in the struct array...
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
Jaime OlivaresCommented:
Hi again, I don't know why you cannot see the  array outside the class. Struct members are public by default, and also you have explicity declared as public.
0
 
rmmarshAuthor Commented:
What would be the syntax for "venueName" or "price"?
0
 
rmmarshAuthor Commented:
never mind... I figured it out (I think)...thanks again...
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

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