?
Solved

Object Class with Array

Posted on 2013-11-05
2
Medium Priority
?
421 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 1000 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

770 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