Solved

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

Posted on 2008-06-19
6
149 Views
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

0
Comment
Question by:rmmarsh
[X]
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
6 Comments
 
LVL 55

Accepted Solution

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

Author Comment

by:rmmarsh
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...

R
0
 

Author Comment

by:rmmarsh
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...
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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.
0
 

Author Comment

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

Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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