What is the cheapest way to execute a LINQ-Query immediately

后端 未结 2 1914
萌比男神i
萌比男神i 2021-01-23 05:17

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

2条回答
  •  鱼传尺愫
    2021-01-23 06:15

    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.

提交回复
热议问题