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++;
}}
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++;
}}
foreach(double r in portfolioReturns)
{
if(-8.0 < r && r < -7.0)
n8++;
}
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.
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
}
You could also use LINQ, in addition to the fix everyone so quickly provided
n8 += portfolioReturns.Count(r => -8.0 < r && r < -7.0);