I discovered a very puzzling behavior for the following code:
public double ReturnBehavior(List<double> ptList)
{
return ptList.Count==0? 0:ptList[0];
}
I thought it should be equivalent to
public double ReturnBehavior(List<double> ptList)
{
if(ptList.Count==0)
return 0;
return ptList[0];
}
But it is not, because the first method will evaluate both true
and false
condition together. So this means that first method will try an IndexOutOfRange
exception if ptList.Count==0
.
Am I missing something here? Or is it a bug in vs 2008?