Click here to Skip to main content
11,581,510 members (60,524 online)
Click here to Skip to main content

Tagged as

Logical and arithmetic operations in C#

, 29 Jun 2011 CPOL 3.1K
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


You may also be interested in...

Comments and Discussions

 
GeneralThe performance problem is that if you have the following op... Pin
Philippe Mori28-Jun-11 14:51
memberPhilippe Mori28-Jun-11 14:51 
GeneralRe: Well, I haven't noticed that functions were used in the alte... Pin
Philippe Mori28-Jun-11 15:12
memberPhilippe Mori28-Jun-11 15: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.150603.1 | Last Updated 29 Jun 2011
Article Copyright 2011 by Mohammad A Rahman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid