How to create initialize and print a list of objects with List<T> Class in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic
 
Public Class Car
    Public Property Name As String
    Public Property Price As Decimal 
End Class  
         
Public Module Module1
    Public Sub Main()
        Dim cars As New List(Of Car) From
        {
            New Car With {.Name = "New 2020 Honda HR‑V SUV", .Price = 30010},
            New Car With {.Name = "2020 Volvo XC60", .Price = 47400},
            New Car With {.Name = "2020 Audi Q3", .Price = 35695},
            New Car With {.Name = "2020 Nissan Murano", .Price = 32625}
        }
 
		For Each theCar As Car In cars
            Console.WriteLine(theCar.Name)
            Console.WriteLine(theCar.Price.ToString & " ")
            Console.WriteLine()
        Next
    End Sub
End Module
 
 
 
' run:
'
' New 2020 Honda HR‑V SUV
' 30010 
 
' 2020 Volvo XC60
' 47400 
 
' 2020 Audi Q3
' 35695 
 
' 2020 Nissan Murano
' 32625
' 
'

 



answered May 5, 2020 by avibootz
edited May 5, 2020 by avibootz

Related questions

1 answer 191 views
2 answers 215 views
1 answer 209 views
1 answer 192 views
1 answer 113 views
3 answers 309 views
4 answers 386 views
...