Why cant i use arraylist.count in this way?

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.
Raul77Asked:
Who is Participating?
 
AllamzCommented:
Raul,

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

Open in new window

0
 
Raul77Author Commented:
Thanks worked :)
0
 
AllamzCommented:
Raul,

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

Best Regards,

Mohamed Allam
Senior Software Engineer
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.