Here's a function I use in a real world app with both.
Public Function GetAllowableValues(ByVal IncludeDescription As
Boolean) As String()
Dim Retval As New ArrayList
For Each row As DataRow In Data.Rows
If IncludeDescription Then
Retval.Add(row(ReturnColumn).ToString & " - " & row
(DescriptionColumn).ToString)
Else
Retval.Add(row(ReturnColumn))
End If
Next
Return CType(Retval.ToArray(GetType(String)), String())
End Function
The For Each uses enumeration to loop over the all the rows in a
DataTable. I add the appropriate string to an ArrayList. At the end
I convert the ArrayList to an array of string and return the list of
allowable values. I could have declared a fixed array of String
(which would honestly be more efficient), or used some other
collection, but ArrayList was just so darn easy to use I couldn't
resist it.
After filling the ArrayList itself, I could have used a "For Each
value as String In Retval" to enumerate over the data in RetVal and do
whatever processing I need to on the strings.
- R.B.Davidson
On Feb 2, 12:00 pm, john <[email protected]> wrote:
> Hi there,
>
> I was yesterday reviewing and re-reading my books, and came up with
> this question.
> I understand concept of enumeration and arraylist in .NET, but can
> somebody provide me with a real business example of both enumeration
> and arraylist? I was trying to find something on the web, but all the
> examples that I was able to find so far were very basic, just to
> explain the idea of each concept.