Use For Each to loop through the ArrayList : ArrayList « Collections « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » Collections » ArrayList 
8. 11. 4. Use For Each to loop through the ArrayList
 
 
Imports System.Collections
Structure Person
    Dim strLastName As String
    Dim strFirstName As String
    Dim strPhone As String
    Dim strEMail As String
End Structure


public class Test
   public Shared Sub Main
        Dim alPersons As New ArrayList
        Dim udtPerson As New Person

        'Add the first person.
        With udtPerson
            .strLastName = "S"
            .strFirstName = "J"
            .strPhone = "5"
            .strEMail = "j@s.com"
        End With
        alPersons.Add(udtPerson)

        'Add the second person.
        With udtPerson
            .strLastName = "J"
            .strFirstName = "S"
            .strPhone = "5"
            .strEMail = "s@s.com"
        End With
        alPersons.Add(udtPerson)

        'Create the third person.
        With udtPerson
            .strLastName = "J"
            .strFirstName = "K"
            .strPhone = "5"
            .strEMail = "k@s.com"
        End With

        'Insert the third person, but first check if they already exists.
        If Not alPersons.Contains(udtPersonThen
            alPersons.Insert(1, udtPerson)
        End If

        'Remove the first person.
        alPersons.RemoveAt(0)

        'Display the array list values.
        Console.WriteLine("The array list contains " & alPersons.Count & " elements.")
        For Each udtPerson In alPersons
            Console.WriteLine("NAME: " & udtPerson.strFirstName & " " & udtPerson.strLastName)
        Next udtPerson



   End Sub
End class

        
  
  




The array list contains 2 elements.
NAME: K J
NAME: S J

 
8. 11. ArrayList
8. 11. 1. Add user defined object to ArrayList
8. 11. 2. Add different data types to ArrayList
8. 11. 3. Use ArrayList to store objects
8. 11. 4. Use For Each to loop through the ArrayList
8. 11. 5. Convert ArrayList to array
8. 11. 6. Use DirectCast to convert ArrayList to array
8. 11. 7. Use ArrayList.Contains to check if a object already exists
8. 11. 8. Remove element in an ArrayList by index
w___w__w__._j_av___a_2s__.___c_o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.