This question came into my mind while generating sample data for a SO-answer.
I don\'t like the verbose way of adding DataRows one by one via Tbl.Rows.Add
, so i\'ve
I'd just rewrite it as a foreach
:
For Each y As String in years
tbl.Rows.Add(y)
Next
It's much more clear what your intention is this way, and it executes right away.
I'd be more tempted to use a List(Of T)
:
Dim years As New List(Of String) From {"2010/2009", "2009/2008", "2008/2007", "2007/2006", "2006/2005", "2005/2004", "2004/2003"}
years.ForEach(Sub(y) tbl.Rows.Add(y))
It's all subjective though, loops are probably most clear for these one liners.