Solved

Object Class with Array

Posted on 2013-11-05
2
414 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
[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
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
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…
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…
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…

724 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