本文介紹了如何一次性刪除通用列表中的所有空元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
.Net 中是否為 C# 定義了一個默認方法來刪除列表中所有 null
的元素?
Is there a default method defined in .Net for C# to remove all the elements within a list which are null
?
List<EmailParameterClass> parameterList = new List<EmailParameterClass>{param1, param2, param3...};
假設一些參數是null
;我無法提前知道,我想從我的列表中刪除它們,以便它只包含不為空的參數.
Let's say some of the parameters are null
; I cannot know in advance and I want to remove them from my list so that it only contains parameters which are not null.
推薦答案
您可能需要以下內容.
List<EmailParameterClass> parameterList = new List<EmailParameterClass>{param1, param2, param3...};
parameterList.RemoveAll(item => item == null);
這篇關于如何一次性刪除通用列表中的所有空元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!