How to convert a list of strings to list of double values in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic
Imports System.Globalization

Public Class Program
	Public Shared Sub Main()
		Dim lst As New List(Of String) From {"3.14", "474.9802", "1.67", "8372.091", "53521.0009"}
		
		Dim lst_dbl As List(Of Double) = New List(Of Double) From {0, 0, 0, 0, 0}

		Dim i As Integer = 0
		Do While (i < lst.Count)
			lst_dbl(i) = Double.Parse(lst(i), CultureInfo.InvariantCulture)
        	i = i + 1
		Loop           
		
		For Each d In lst_dbl
		    Console.WriteLine(d)
        Next
    End Sub
End Class





' run:
'
' 3.14
' 474.9802
' 1.67
' 8372.091
' 53521.0009
'

 



answered Nov 14, 2021 by avibootz
...