Why cant i use arraylist.count in this way?

Posted on 2009-02-08
Last Modified: 2013-12-16
Hi ,
i am storing an arraylist in application state and when i try to get the count i get the an error any idea?

Below is my code.
        ArrayList myList = (ArrayList)Application["V"];
        if (myList.Count == 0)
        { Response.Write("something"); }

Error : Object reference not set to an instance of an object.
Question by:Raul77
    LVL 6

    Accepted Solution


    please try below
    ArrayList myList = new ArrayList();
    myList = (ArrayList)Application["V"];
    if(myList != null)
            if (myList.Count == 0)
            { Response.Write("something"); }
    Response.Write("ArrayList Is Empty"); 

    Open in new window


    Author Closing Comment

    Thanks worked :)
    LVL 6

    Expert Comment


    You are more than welcome, Please don't hesitate to contact me if you require further assistance.

    Best Regards,

    Mohamed Allam
    Senior Software Engineer

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    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…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now