LINQ All Operator

By Peter Bromberg

The All operator checks whether all elements of a sequence satisfy a condition

Employee employee =
        new Employee { ID = 1, Name =
             "Jones", DepartmentID = 1 };

Func<Employee, bool>[] validEmployeeRules =
{
    e => e.DepartmentID > 0,
    e => !String.IsNullOrEmpty(e.Name),
    e => e.ID > 0
};


bool isValidEmployee =  validEmployeeRules.All(rule => rule(employee));

LINQ All Operator  (799 Views)