Solved

Object Class with Array

Posted on 2013-11-05
2
410 Views
Last Modified: 2013-11-05
OK everyone- I am going in too many different directions at once and I know I am missing something simple- here is my issue- I am getting an "object reference not set to an instance of an object" error and I know I a missing something obvious  below are my object classes and how I am trying to call them:

public class ItemDiscountRequest
    {
        public string ItemName;

        public int Quantity;

        public ItemDiscountRequest()
        {

        }

    }

 public class DiscountRequest
    {
        public string CustID;
       
        public ItemDiscountRequest[] Items;
           }
Then I am using them with a web method to get customer discounts---

ItemDiscountRequest discountReq = new ItemDiscountRequest();
DiscountRequest trevReq = new DiscountRequest();
           
            discountReq.ItemName = "ITEMSKU";
            discountReq.Quantity = 2;

            trevReq.Items[0] = discountReq;


            GetDiscount(trevReq);


HELP- I know I am missing something simple can someone point it out so I can feel dumb and then move on to getting things working? ;-) lol  Thanks in advance
0
Comment
Question by:jmr71
2 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 250 total points
ID: 39625559
You need to provide an array item:
trevReq.Items = new ItemDiscountRequest[1];
trevReq.Items[0] = discountReq;

Open in new window


You can't assign an item to a non-initialized array. Basically:

object[] myObjectArray;

has myObjectArray = null. You need:

object[] myObjectArray = new object[someNumber];

Otherwise, you have no place to put the objects.
0
 

Author Comment

by:jmr71
ID: 39625571
ACK! I did that every which way but that- I knew it was something simple....ok walking way...lookin guilty ...awarding points....sayin thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

829 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