Is there a default method defined in .Net for C# to remove all the elements within a list which are null
?
List parame
List<EmailParameterClass> parameterList = new List<EmailParameterClass>{param1, param2, param3...};
parameterList = parameterList.Where(param => param != null).ToList();
Easy and without LINQ:
while (parameterList.Remove(null)) {};
The method OfType()
will skip the null values:
List<EmailParameterClass> parameterList =
new List<EmailParameterClass>{param1, param2, param3...};
IList<EmailParameterClass> parameterList_notnull =
parameterList.OfType<EmailParameterClass>();
I do not know of any in-built method, but you could just use linq:
parameterList = parameterList.Where(x => x != null).ToList();
The RemoveAll method should do the trick:
parameterList.RemoveAll(delegate (object o) { return o == null; });
You'll probably want the following.
List<EmailParameterClass> parameterList = new List<EmailParameterClass>{param1, param2, param3...};
parameterList.RemoveAll(item => item == null);