Insafian Insafian - 1 year ago 111
C# Question

LINQ query for list

I have a list

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

Is there a way I can use any
query to check this in an

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download