65.9K
CodeProject is changing. Read more.
Home

Logical and arithmetic operations in C#

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Jun 28, 2011

CPOL
viewsIcon

9809

The code has been updated to improve the performance:public static bool DoSequenceOfOr(params Func[] sequenceOfBooleanValue){ foreach (Func item in sequenceOfBooleanValue) if (item()) return true; return false;}public static bool...

The code has been updated to improve the performance:
public static bool DoSequenceOfOr(params Func<bool>[] sequenceOfBooleanValue)
{
    foreach (Func<bool> item in sequenceOfBooleanValue)
        if (item())
            return true;
    return false;
}

public static bool DoSequenceOfAnd(params Func<bool>[] sequenceOfBooleanValue)
{
    foreach (Func<bool> item in sequenceOfBooleanValue)
        if (!item())
            return default(bool);
    return true;
}
Usage:
bool result1 = Operation.DoSequenceOfAnd(MethodOne, MethodTwo, MethodThree)
bool result2 = Operation.DoSequenceOfOr(MethodOne, MethodTwo, MethodThree)
Logical and arithmetic operations in C# - CodeProject