Solved

Object Class with Array

Posted on 2013-11-05
2
407 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 19

Accepted Solution

by:
Daniel Van Der Werken earned 250 total points
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

771 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

7 Experts available now in Live!

Get 1:1 Help Now