How to remove all empty strings from a list in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
 
class Program
{
    static void Main() {
        var list = new List<string> { "c++", "c#", "", "c", "", "java", "php", "" };
 
        Console.WriteLine(string.Join(',', list));
         
        list.RemoveAll(item => item == "");
         
        Console.WriteLine(string.Join(',', list));
    }
}
 
 
 
 
/*
run:
 
c++,c#,,c,,java,php,
c++,c#,c,java,php
 
*/

 

 



answered Feb 12, 2024 by avibootz

Related questions

1 answer 180 views
1 answer 84 views
1 answer 165 views
1 answer 162 views
1 answer 158 views
...