Reputation: 38940
Wow...I've never seen this before. Any way to get around it?
foreach( double r in portfolioReturns)
{
if (-8.0 < r < -7.0)
{
n8++;
}}
Upvotes: 4
Views: 7489
Reputation: 68687
You could also use LINQ, in addition to the fix everyone so quickly provided
n8 += portfolioReturns.Count(r => -8.0 < r && r < -7.0);
Upvotes: 3
Reputation: 720
You are effectively doing this
if ((-8.0 < r) < -7.0)
Since (-8.0 < r) evaluates to a boolean, you can't compare it to a float. Do this instead:
if (-8.0 < r && r < -7.0) {
//code here
}
Upvotes: 13
Reputation: 42208
let me guess, you are coming from python? It is the only language I know of where that works :-)
looking at (-8.0 < r < -7.0)
, first, -8.0 < r gets evaluated, which is true. true < -7.0 barfs.
Upvotes: 3
Reputation: 245429
foreach(double r in portfolioReturns)
{
if(-8.0 < r && r < -7.0)
n8++;
}
Upvotes: 1