Search code examples
.netvariablesinline-code

Use temp variable or inline in this example?


I'm loading an ASP.NET dropdown list.

Is there any advantage to doing this::

    Private Sub LoadSeasonsListbox(ByVal seasons As List(Of Season))
      Dim li As ListItem
      For Each s As Season In seasons
        li = New ListItem(s.SeasonDescription, s.SeasonCodeID)
        frm.SeasonsList.Items.Add(li)
      Next
    End Sub

over this:

Private Sub LoadSeasonsListbox(ByVal seasons As List(Of Season))
    For Each s As Season In seasons
        frm.SeasonsList.Items.Add(New ListItem(s.SeasonDescription, s.SeasonCodeID))
    Next
End Sub

Solution

  • When debugging, the first makes it easier to examine the ListItem being added.

    The first also has a lower width which some may find easier to read (but a higher height which some may find harder to read...)