RhythmAddict112
Programmer
Hey boys 'n girls -
Real quick Q..
Formally, I was coding my loop through a data table like...
However...I need to exit my for loop when I hit 5 rows. As a quick fix I'm doing it like this...
So my question...is the 2nd way much worse/less performant/messier than the first? Is there an easy way for me to get the row number in the first method? Thanks!
Real quick Q..
Formally, I was coding my loop through a data table like...
Code:
Dim s As New List(Of String)(dt.Rows.Count)
Dim dr As DataRow
For Each dr In dt.Rows
s.Add(dr("FirstName").ToString)
Next
Return s.ToArray
However...I need to exit my for loop when I hit 5 rows. As a quick fix I'm doing it like this...
Code:
Dim s As New List(Of String)(dt.Rows.Count)
For i As Int16 = 0 To dt.Rows.Count - 1
If i > 4 Then Exit For
s.Add(dt.Rows(i).Item(0))
Next
So my question...is the 2nd way much worse/less performant/messier than the first? Is there an easy way for me to get the row number in the first method? Thanks!