Copies the elements of the ArrayList to a new array of the specified element type. : ArrayList « Data Structure « VB.Net






Copies the elements of the ArrayList to a new array of the specified element type.

 


Imports System
Imports System.Collections
Public Class SamplesArrayList
    Public Shared Sub Main()
        Dim myAL As New ArrayList()
        myAL.Add("A")
        myAL.Add("B")
        myAL.Add("C")
        myAL.Add("D")
        myAL.Add("E")
        PrintIndexAndValues(myAL)

        Dim myArr As String() = CType(myAL.ToArray(GetType(String)), String())
        PrintIndexAndValues(myArr)
    End Sub 'Main

    Overloads Public Shared Sub PrintIndexAndValues(myList As ArrayList)
        Dim i As Integer = 0
        Dim o As [Object]
        For Each o In  myList
            Console.WriteLine("        [{0}]:    {1}", i, o)
            i = i + 1
        Next o
    End Sub

    Overloads Public Shared Sub PrintIndexAndValues(myArr() As String)
        Dim i As Integer
        For i = 0 To myArr.Length - 1
            Console.WriteLine("        [{0}]:    {1}", i, myArr(i))
        Next i
        Console.WriteLine()
    End Sub

End Class

   
  








Related examples in the same category

1.Store Objects into ArrayListStore Objects into ArrayList
2.ArrayList: add, remove, IndexOf, Count, Contains, TrimToSize, GetEnumeratorArrayList: add, remove, IndexOf, Count, Contains, TrimToSize, GetEnumerator
3.Add element to an ArrayList and get its LengthAdd element to an ArrayList and get its Length
4.Convert ArrayList to Array
5.Store different Class in an ArrayListStore different Class in an ArrayList
6.Use ArrayList to Store your own classUse ArrayList to Store your own class
7.ArrayList Class Implements the IList interface
8.Adds an object to the end of the ArrayList.
9.ArrayList.BinarySearch Searches the entire sorted ArrayList for an element using the default comparer
10.ArrayList.BinarySearch (Object, IComparer)
11.ArrayList.Clear removes all elements from the ArrayList.
12.ArrayList.CopyTo copies the entire ArrayList to a compatible one-dimensional Array, starting at the beginning of the target array.
13.ArrayList.FixedSize returns an ArrayList wrapper with a fixed size.
14.ArrayList.GetEnumerator returns an enumerator for a range of elements in the ArrayList.
15.ArrayList.GetRange returns an ArrayList which represents a subset of the elements in the source ArrayList.
16.ArrayList.IndexOf searches for the specified Object and returns the zero-based index
17.ArrayList.Insert inserts an element into the ArrayList at the specified index.
18.ArrayList.IsReadOnly Property tells whether the ArrayList is read-only.
19.ArrayList.IsSynchronized Property tells whether access to the ArrayList is synchronized (thread safe).
20.ArrayList.Item Property gets or sets the element at the specified index.
21.ArrayList.LastIndexOf searches for Object and returns the zero-based index of the last occurrence
22.ArrayList.Remove removes the first occurrence of a specific object from the ArrayList.
23.ArrayList.Repeat Method returns an ArrayList whose elements are copies of the specified value.
24.Reverses the order of the elements in the entire ArrayList.
25.Sorts the elements in the ArrayList using the specified comparer.
26.Sorts the elements in a range in ArrayList using the specified comparer.
27.Sorts the elements in the entire ArrayList.
28.Reverses the order of the elements in a range.