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

Posted on 2008-06-19
Last Modified: 2013-12-16
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

Question by:rmmarsh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 55

Accepted Solution

Jaime Olivares earned 500 total points
ID: 21826925
it should be:
pD.venueBookInfo= new bookInfoByVenue[100] ;

Author Comment

ID: 21826977
Damn!  you are good Jaime... thanks so much... I really appreciate it...  I knew there had to be a way to do this...


Author Comment

ID: 21827071
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...
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

LVL 55

Expert Comment

by:Jaime Olivares
ID: 21827101
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.

Author Comment

ID: 21827108
What would be the syntax for "venueName" or "price"?

Author Comment

ID: 21827138
never mind... I figured it out (I think)...thanks again...

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

615 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