If possible, I might prefer to do something like this:
IEnumerable<decimal> GetBalances()
{
decimal budgetRemaining = 0M;
// calculate budget remaining
yield return budgetRemaining;
decimal totalOpenInvoices = 0M;
// calculate the total of the open invoices
yield return totalOpenInvoices;
// ... calculate and yield any other balances that require consideration
}
and then I could write the if statement like this:
if (this.GetBalances().Any(balance => balance != 0M))
{
}
Note: I doubt that I would use this approach if I only needed to check 2 balances, but I might do this if I had very many different balances that needed to be checked.
Original Answer
EDIT: The comment on the question indicates that the totalOpenInvoices variable represents the total monetary amount of the open invoices, therefore this answer doesn't really apply to the question. I'll leave it here, though, as I feel that the argument would still be valid for the situation described in this answer.
Does totalOpenInvoices represent the sum of the monetary amount of the open invoices, or is it just the number of invoices that are open?
If the latter, then one reason why I don't like this approach is because you're sort of comparing apples and oranges. You're saying that the check budgetRemaining != 0
is similar in nature to the check totalOpenInvoices != 0
, and the only difference is the input variable (either budgetRemaining or totalOpenInvoices).
I'll try illustrate why this doesn't make sense to me by breaking the if statement down in a different way. I'll move the != 0
code out into a delegate called stillHasMoney:
Func<decimal, bool> stillHasMoney = (amount) => amount != 0;
if (stillHasMoney(budgetRemaining) || stillHasMoney(totalOpenInvoices))
{
}
Now, does this code still make sense? If totalOpenInvoices represents the number of open invoices, not the sum of the monetary amount of the open invoices, then this code doesn't seem correct to me. It's like saying "I had 5 turtles and gave away 2. How much money is left?" Similarly, this code is saying "I had 5 open invoices and closed 2. How much money is left?" Granted, invoices translate to money more easily than turtles, but the point is, do you care about the number of open invoices or the sum of their monetary value?