How can I check for NULL value in lambda expression having ForEach and Find methods.
For instance I've a below method which takes a comma separated list of values, iterate through them and for each value finds a SelectListItem which if found is marked as Selected. The issue comes when no matching item is found and it throws null reference exception.
private static void MarkListItemsSelected(string param, IList<SelectListItem> items)
{
var filters = param.Split(';');
filters.ToList()
.ForEach(x => items.ToList()
.Find(y => y.Text.ToUpper().Equals(x.ToUpper()))
.Selected = true);
}
ToList(), it will split into anArray.ForEachmethod.foreachso why create aListforForEachwhen you could just doforeach.ForEachis an abomination, but your comment sounded like they could just remove theToList.