Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Check array list is fixed size, is synchronized, is read only and trim the array list in VB and C# .net.

Author: Maliha Atteeq
Download Source Code : 979_ARRAYLIST.zip

In this simple article you will learn that how we can check that array list has fixed size or not and it is synchronized or not and whether the array list is read only and also trim the list to actua

 Check Size Is Fixed Or Not:

To check that array list has fixed size or not, array list provides us the property named IsFixedSize. It will return true if the list has fixed size and it will return false if it does not.

To demonstrate second ways make a window application. Drag one button on the form, press button.

Now write the following code on button click event:

C#:

private void button1_Click(object sender, EventArgs e)

        {

            if (obj.IsFixedSize)

            {

                MessageBox.Show("array list has fixed size");

            }

            else

            {

                MessageBox.Show("array list has variable size");

 

            }

        }

VB:

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    If obj.IsFixedSize Then

        MessageBox.Show("array list has fixed size")

    Else          

        MessageBox.Show("array list has variable size")

    End If

End Sub

 

Check array list is read only or not:

To check that array list is read only or not, array list class provides us the property named IsReadOnly. Its return type is Boolean means it will return true if the list is read only and it will return false if it does not.

To demonstrate second ways make a window application. Drag one button on the form, press button.

Now write the following code on button click event:

C#:

private void btn_read_Click(object sender, EventArgs e)

        {

            if (obj.IsReadOnly)

            {

                MessageBox.Show("array list is read only");

            }

            else

            {

                MessageBox.Show("array list is not just read only");

               

            }

        }

VB:

Private Sub btn_read_Click(ByVal sender As Object, ByVal e As EventArgs)

        If obj.IsReadOnly Then

            MessageBox.Show("array list is read only")

        Else

 

            MessageBox.Show("array list is not just read only")

        End If

    End Sub

Check list is synchronized or not:

To check that array list is synchronized or not, array list class provides us the property named IsSynchronized. Its return type is Boolean which means it will return true if the list is synchronized and it will return false if it does not. The concept of this property is related with threads.

To demonstrate second ways make a window application. Drag one button on the form, press button.

Now write the following code on button click event:

C#:

private void btn_sync_Click(object sender, EventArgs e)

        {

            if (obj.IsSynchronized)

            {

                MessageBox.Show("array list is synchronised");

            }

            else

            {

                MessageBox.Show("array list is not synchronised");

            }

        }

 

VB:

Private Sub btn_sync_Click(ByVal sender As Object, ByVal e As EventArgs)

        If obj.IsSynchronized Then

            MessageBox.Show("array list is synchronised")

        Else

            MessageBox.Show("array list is not synchronised")

        End If

    End Sub

Trim the array list:

In order to trim the array list, array list class provides us a function TrimToSize() which takes no parameters and its return type is void.  This function sets the capacity to the actual number of elements in the list.

To demonstrate second ways make a window application. Drag one button on the form, press button.

Now write the following code on button click event:

C#:

private void btn_trim_Click(object sender, EventArgs e)

        {

            obj.TrimToSize();

            MessageBox.Show("array list is trimed");

       }

VB:

Private Sub btn_trim_Click(ByVal sender As Object, ByVal e As EventArgs)

        obj.TrimToSize()     

              MessageBox.Show("the list is trimed")

    End Sub

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP ARRAYLIST APPLICATION";

            obj.Add(10);

            obj.Add(20);

            obj.Add(30);

            obj.Add(40);

            obj.Add(50);

            obj.Add(60);           

        }

VB:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP ARRAYLIST APPLICATION"

        obj.Add(10)

        obj.Add(20)

        obj.Add(30)

        obj.Add(40)

        obj.Add(50)

        obj.Add(60)

    End Sub

This simple article tells that how we can check that array list has fixed size or not and it is synchronized or not and whether the array list is read only and also trim the list to actual size using “array list” class in Vb and c#.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Getting index of specific value in array list using “array list” class in vb and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net