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
 

Removing value on given index and getting type of array list using “array list” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 980_arraylist6.zip

In this simple article you will learn that how we can remove the given value and from the given index from array list and how to get the type of array list using “array list” class in Vb and c#.net.

 Remove a value from array list:

To remove a given value from the list, array list class provides a function remove()  which takes object value as a parameter and remove the given value from the list. Its return type is void.

To demonstrate make a new window application. Drag one button and a text box on from.

Now write the following code on Button click event:

C#:

private void btn_rem_Click(object sender, EventArgs e)

        {

            string temp;

            temp = textBox1.Text;

            int ob = Convert.ToInt16(temp);

            obj.Remove(a);

            MessageBox.Show("given value is removed from the list");

        }

VB:

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

        Dim temp As String

        temp = textBox1.Text

        Dim ob As Integer = Convert.ToInt16(temp)

        obj.Remove(a)

        MessageBox.Show("given value is removed from the list")

    End Sub

Remove a value from specific index:

To remove a value from the specific index of array list, array list class provide a function removeAt() which takes an integer value as an index and remove the value from that specific index. Its return type is void. This function returns nothing.

To demonstrate make a new window application. Drag one button and a text box on from.

Now write the following code on Button click event:

C#:

private void button1_Click(object sender, EventArgs e)

        {

            string temp;

            temp = txt_index.Text;

            int index = Convert.ToInt16(temp);

            obj.RemoveAt(index);

            MessageBox.Show("value is removed from the specific index");

        }

VB:

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

        Dim temp As String

        temp = txt_index.Text

        Dim index As Integer = Convert.ToInt16(temp)

        obj.RemoveAt(index)

        MessageBox.Show("value is removed from the specific index")

    End Sub

Remove values from specific range:

To remove values within the specific range of array list, array list class provide a function removeRange() which takes two parameters as an argument, one is the index and the second is the count. It will remove the values from the index you specified as an argument and will continue removing till the count you specified. Its return type is void. This function returns nothing.

To demonstrate make a new window application. Drag one button and two text boxes on from.

Now write the following code on Button click event:

C#:

private void btn_remRange_Click(object sender, EventArgs e)

        {

            string index;

            string count;

            int index;

            int count;

            index =convert.ToInt16( txt_ind.Text);

            count = convert.ToInt16(txt_count.Text);

            obj.RemoveRange(index, count);

            MessageBox.Show("values are removed within the given range");

        }

 

VB:

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

       

Dim index As Integer

        Dim count As Integer

        index =  Convert.ToInt16(txt_ind.Text)

        count = Convert.ToInt16(txt_count.Text)

       

obj.RemoveRange(index, count)

 

        MessageBox.Show("values are removed within the given range")

    End Sub

Get type:

In order to get the type of the array list, array list class provides us a function named as getType(). This function takes no argument as parameter and its return type is type means it return the object of class type which tell you the type of the object.

To demonstrate make a new window application. Drag one button on from.

Now write the following code on Button click event:

C#:

private void btn_type_Click(object sender, EventArgs e)

        {

           Type ob=obj.GetType();

           string temp = Convert.ToString(ob);

           MessageBox.Show("type is:"+temp);

        }

VB:

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

        Dim ob As Type = obj.[GetType]()

        Dim temp As String = Convert.ToString(ob)

        MessageBox.Show("type is:" & temp)

    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);           

        }

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)      

    End Sub

This simple article tells how we can remove the given value and from the given index from array list and how to get the type of array list using “array list” class in Vb and c#.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Check array list is fixed size, is synchronized, is read only and trim the array list in VB and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net