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

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

    The method OfType() will skip the null values:

    List parameterList =
        new List{param1, param2, param3...};
    
    IList parameterList_notnull = 
        parameterList.OfType();
    

提交回复
热议问题