Insafian Insafian - 4 months ago 21
C# Question

Check null value in a list using linq

I have a list

List<OfferComparison> Comparison
. I want to
check if all the items have
Value == null
in an

How can I do it with linq?

public class OfferComparison : BaseModel
public string Name { get; set; }
public string Value { get; set; }
public bool Valid { get; set; }


Using linq method of All:

var result = Comparison.All(item => item.Value == null)

Basically what it does is to iterate all items of a collection and check a predicate for each of them. If one does not match - result is false