Logical and arithmetic operations in C#





5.00/5 (1 vote)
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)