?
Solved

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

Posted on 2008-06-19
6
Medium Priority
?
152 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 2000 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
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

718 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