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

前端 未结 7 571
囚心锁ツ
囚心锁ツ 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:17

    You'll probably want the following.

    List parameterList = new List{param1, param2, param3...};
    parameterList.RemoveAll(item => item == null);
    

提交回复
热议问题