How to remove all the null elements inside a generic list in one go?

前端 未结 7 537
囚心锁ツ
囚心锁ツ 2020-12-07 21:28

Is there a default method defined in .Net for C# to remove all the elements within a list which are null?

List parame         


        
7条回答
  •  囚心锁ツ
    2020-12-07 22:12

    The RemoveAll method should do the trick:

    parameterList.RemoveAll(delegate (object o) { return o == null; });
    

提交回复
热议问题