BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Test If ArrayList Control Has Zero Elements?

ArrayList is very useful class which you can use to manipulate collection of items in memory. You can add new items by using its Add() method.

One of common problems is how to check if ArrayList contains any element. Fortunately, solution is simple. To get number of ArrayList elements you need to use its Count() read only property. You can use this ASP.NET sample server side code:

[ C# ]

// To use ArrayList, we need this namespace
using System.Collections;
 
public partial class DefaultCS : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // Declaration and instatiation of ArrayList
        ArrayList MyList = new ArrayList();
 
        // Check is there any elements in ArrayList
        if (MyList.Count == 0)
        {
            // ArrayList has no elements
        }
        else
        {
            // In this case, array list is not empty
        }
 
    }
}

[ VB.NET ]

' To use ArrayList, we need this namespaces
Imports System.Collections
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Declaration and instatiation of ArrayList
        Dim MyList As ArrayList = New ArrayList()
 
        ' Check is there any elements in ArrayList
        If MyList.Count = 0 Then
            ' ArrayList has no elements
        Else
            ' In this case, array list is not empty
        End If
    End Sub
End Class



Related articles:

1. Debugging with "Stepping" and "Data Viewing" features

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.