Solved

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

Posted on 2008-06-19
6
144 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now