Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Logical and arithmetic operations in C#

, 29 Jun 2011 CPOL
Rate this:
Please Sign up or sign in to 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)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


Comments and Discussions

 
GeneralThe performance problem is that if you have the following op... PinmemberPhilippe Mori28-Jun-11 15:51 
GeneralRe: Well, I haven't noticed that functions were used in the alte... PinmemberPhilippe Mori28-Jun-11 16:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411028.1 | Last Updated 29 Jun 2011
Article Copyright 2011 by Mohammad A Rahman
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid