Insafian Insafian - 1 year ago 106
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; }

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