How to convert a list of strings to list of int in VB.NET

2 Answers

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim list As List(Of String) = New List(Of String) From {
            "1",
            "2",
            "3",
            "4",
            "5"
        }
		
        Dim result As List(Of Integer) = list.Select(AddressOf Integer.Parse).ToList()
		
        Console.WriteLine(String.Join(", ", result))
    End Sub
End Class



' run:
'
' 1, 2, 3, 4, 5
'

 



answered Jul 29, 2023 by avibootz
0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim list As List(Of String) = New List(Of String) From {
            "1",
            "2",
            "3",
            "4",
            "5"
        }
		
        Dim result As List(Of Integer) = list.ConvertAll(AddressOf Integer.Parse)
		
        Console.WriteLine(String.Join(", ", result))
    End Sub
End Class



' run:
'
' 1, 2, 3, 4, 5
'

 



answered Jul 29, 2023 by avibootz
...