How to extract the integers from a list of objects using Linq in VB.NET

1 Answer

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

Public Class Program
	Public Shared Sub Main()
        Dim list = New List(Of Object) From {
            3,
            7,
            "vb",
            8,
            "c",
            99,
            10,
            "c++",
            -5,
            1,
            "java",
            2
        }
        Dim result As List(Of Integer) = list.OfType(Of Integer)().ToList()
		
        Console.WriteLine(String.Join(", ", result))
    End Sub
End Class

	
	
	
' run:
'
' 3, 7, 8, 99, 10, -5, 1, 2
'

 



answered Sep 27, 2023 by avibootz
edited Sep 27, 2023 by avibootz
...