- 12345
Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Looping using an Enumerator
From Wiki
Summary: Looping using an Enumerator
An iEnumerator object can be used on any object that implements iEnumerable. This can come in very handy as you will find many objects do implement this. As a simple example, here's a way you can add items to an ArrayList and then iterate through the item collection using an iEnumerator:
- Partial Class Default1
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- ' Example array list
- Dim MyList As New ArrayList
- MyList.Add(1)
- MyList.Add(2)
- MyList.Add(3)
- MyList.Add(4)
- MyList.Add(5)
- ' Create an iEnumerator object
- Dim iEnum As IEnumerator = MyList.GetEnumerator
- ' Loop through the data using the iEnumerator
- While iEnum.MoveNext
- Response.Write(CInt(iEnum.Current))
- End While
- End Sub
- End Class
Output:
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.