How to remove all null elements from a list in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic
 
Public Class Program
    Public Shared Sub Main()
        Dim list = New List(Of String) From {
            "c++",
            "c#",
            Nothing,
            "c",
            Nothing,
            "java",
			"vb.net",
            Nothing
        }
         
        Console.WriteLine(String.Join(","c, list))
         
        list.RemoveAll(Function(item) item Is Nothing)
         
        Console.WriteLine(String.Join(","c, list))
    End Sub
End Class
 
 
 
 
' run:
'
' c++,c#,,c,,java,vb.net,
' c++,c#,c,java,vb.net
'

 



answered Feb 12, 2024 by avibootz
edited Feb 12, 2024 by avibootz
...