-1

I am bit confused what is the meaning of below statements.

List<Func<GroupInfoInfo, bool>>()

Groups.Instance.GetGroup(2, grp => TestPredicateGroup(whereCls, grp));

private static bool TestPredicateGroup(List<Func<GroupInfoInfo, bool>> predicates, GroupInfoInfo ri)
{
    foreach (var p in predicates)
    {
        if (!p(ri))
        {
            return false;
        }
    }
    return true;
}

I want to know what is the meaning of List<Func<GroupInfoInfo, bool>>() and statement of if (!p(ri)) in function?

Some confusion in GetGroup() lambda expression also.

skiskd
  • 423
  • 2
  • 9
  • 20
  • [List](https://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx) is a `Generic Collection` type in `C#`. – Arghya C Dec 21 '15 at 13:15
  • `predicates` is a List of function who return a boolean value. So it is correct to call them in a `foreach` like that : `!p(ri)` – Xavier W. Dec 21 '15 at 13:16

1 Answers1

4

List<Func<RoleInfo, bool>> is a list of functions that take a RoleInfo as first and only parameter and returns a bool.

foreach (var p in predicates) iterates over all the functions (predicates), assigns them to p and checks them with !p(ri).

!p(ri) actually is a call to a method / delegate (assigned to variable p), giving the first argument ri which is a RoleInfo. The result is negated, so if it returns false, the result of the if is true. In that case, it will return false. Else it will go on to the next one and test that until it has checked all predicates. If they all return true, the end result of the TestPredicateGroup method is true.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325