Solved

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

Posted on 2008-06-19
6
145 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now