Hi Sarasalvi,
Refer below sample.
Code
C#
protected void Remove(object sender, EventArgs e)
{
List<SamplingCS> returnlis = new List<SamplingCS>();
returnlis.Add(new SamplingCS { customerid = null, Name = null, Country = null });
returnlis.Add(new SamplingCS { customerid = null, Name = "Test", Country = "India" });
// Check if all property in SamplingCS is null then remove.
returnlis.RemoveAll(x => x.GetType()
.GetProperties()
.Select(p => p.GetValue(x, null))
.All(p => p == null));
}
public class SamplingCS
{
public string customerid { get; set; }
public string Name { get; set; }
public string Country { get; set; }
}
VB.Net
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 = "Test",
.Country = "India"
})
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