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
 

How we can check that sorted list has fixed size or not and it is synchronized or not and also trim the list to actual size only using “sorted list” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 964_sortedlist5.zip

In this simple article you will learn that how we can check that sorted list has fixed size or not and it is synchronized or not and also trim the list to actual size using “sorted list” class in Vb a

 Check Size Is Fixed Or Not:

To check that sorted list has fixed size or not, sorted list provide us the facility to check this property by using 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)

        {

            bool temp = obj.IsFixedSize;

            MessageBox.Show(temp.ToString());

        }

 

VB:

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

        Dim temp As Boolean = obj.IsFixedSize

        MessageBox.Show(temp.ToString())

End Sub    

Check list is synchronized or not:

To check that sorted list is synchronized or not, sorted list class provides us the facility to check this property by using IsSynchronized. It will return true if the list is synchronized and it will return false if it does not. 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 button2_Click(object sender, EventArgs e)

        {

            bool temp = obj.IsSynchronized;

            MessageBox.Show(temp.ToString());

        }

VB:

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

        Dim temp As Boolean = obj.IsSynchronized

        MessageBox.Show(temp.ToString())

    End Sub

How to trim the list:

In order to trim the sorted list, sorted 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 button3_Click(object sender, EventArgs e)

        {

            obj.TrimToSize();

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

        }

 

VB:

Private Sub button3_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 SORTED LIST APPLICATION";

            obj.Add(0, 10);

            obj.Add(1, 20);

            obj.Add(2, 30);

            obj.Add(3, 40);

            obj.Add(4, 50);

            obj.Add(5, 60);

        }

VB

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

        Me.Text = "DEVASP SORTED LIST APPLICATION"

        obj.Add(0, 10)

        obj.Add(1, 20)

        obj.Add(2, 30)

        obj.Add(3, 40)

        obj.Add(4, 50)

        obj.Add(5, 60)

    End Sub

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

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to set and get the capacity and count of the sorted list and how we can check that sorted list is read only using “sorted list” class in vb and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net