ArrayList property comes out as null

I have a class: Basket.cs and i created a property for it like this:

public ArrayList basketPayments
        {
            get;
            set;
        }

In my page1.aspx, I want to populate this arraylist so I did this:

 Basket.PaymentMethod = card;
 Basket.basketPayments.Add(card);

but the second like Basket.basketPayments.Add(card);  gives me object null error. How can I use it??
LVL 8
CamilliaAsked:
Who is Participating?
 
JimBrandleyConnect With a Mentor Commented:
It has not been initialized. So, your first get returns the null.

In the class that contains this, add a member:
private ArrayList mBasketPayments = null;

Then change the getter and setter as:

public ArrayList basketPayments
{
      get
     {
           if (mBasketPayments == null)
                mBasketPayments = new ArratList(10);
           return mBasketPayments;
     }
     set { mBasketPayments = value; }
}

Jim
0
 
burakiewiczConnect With a Mentor Commented:
try this
Basket.PaymentMethod = card;
 Basket.basketPayments=new ArrayList();
 Basket.basketPayments.Add(card);
0
 
burakiewiczCommented:
or on the constructor for your basket class add
basketPayments=new ArrayList();
0
 
CamilliaAuthor Commented:
thanks, let me try.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.