ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Remove all NULL elements inside Generic List using C# and VB.Net<p>Hi <a class="username" rel="Sarasalvi"> Sarasalvi</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Remove(object sender, EventArgs e) { List&lt;SamplingCS&gt; returnlis = new List&lt;SamplingCS&gt;(); returnlis.Add(new SamplingCS { customerid = null, Name = null, Country = null }); returnlis.Add(new SamplingCS { customerid = null, Name = &#34;Test&#34;, Country = &#34;India&#34; }); // Check if all property in SamplingCS is null then remove. returnlis.RemoveAll(x =&gt; x.GetType() .GetProperties() .Select(p =&gt; p.GetValue(x, null)) .All(p =&gt; p == null)); } public class SamplingCS { public string customerid { get; set; } public string Name { get; set; } public string Country { get; set; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Remove(ByVal sender As Object, ByVal e As EventArgs) Dim returnlis As List(Of SamplingCS) = New List(Of SamplingCS)() returnlis.Add(New SamplingCS With { .customerid = Nothing, .Name = Nothing, .Country = Nothing }) returnlis.Add(New SamplingCS With { .customerid = Nothing, .Name = &#34;Test&#34;, .Country = &#34;India&#34; }) returnlis.RemoveAll(Function(x) x.GetType().GetProperties().Select(Function(p) p.GetValue(x, Nothing)).All(Function(p) p Is Nothing)) End Sub Public Class SamplingCS Public Property customerid As String Public Property Name As String Public Property Country As String End Class</pre> <p>&nbsp;</p>, 15 Apr 2019 06:04:24 GMT