Remove all empty elements from string array

前端 未结 4 1159
误落风尘
误落风尘 2020-12-29 01:44

I have this:

List s = new List{\"\", \"a\", \"\", \"b\", \"\", \"c\"};

I want to remove all the empty elements

4条回答
  •  心在旅途
    2020-12-29 02:23

    You can use List.RemoveAll:

    C#

    s.RemoveAll(str => String.IsNullOrEmpty(str));
    

    VB.NET

    s.RemoveAll(Function(str) String.IsNullOrEmpty(str))
    

提交回复
热议问题