Solved

ArrayList property comes out as null

Posted on 2009-04-02
4
332 Views
Last Modified: 2012-08-14
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??
0
Comment
Question by:Camillia
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:burakiewicz
burakiewicz earned 200 total points
ID: 24054578
try this
Basket.PaymentMethod = card;
 Basket.basketPayments=new ArrayList();
 Basket.basketPayments.Add(card);
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 24054584
or on the constructor for your basket class add
basketPayments=new ArrayList();
0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 300 total points
ID: 24054593
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
 
LVL 7

Author Comment

by:Camillia
ID: 24055414
thanks, let me try.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

26 Experts available now in Live!

Get 1:1 Help Now