C
Curious
I have a simple method that does a search. Details below:
"mBenchmarkPriceList" is an ArrayList with each element being of
"BenchmarkPrice" type. There are three members in "BenchmarkPrice":
Ticker, Side, and AggregateLists.
The member, "AggregateLists", however, is an ArrayList with each
element being a "BMarkUnit" type. "BMarkUnit" contains two members,
ListName and OriginalWeight.
The method, "GetOriginalWeight", searches through the entire
"mBenchmarkPriceList". If a match of Ticker, Side, and also ListName
is found, it will return "OriginalWeight".
In order to be efficient, once a match is found, I "break" both loops
and return the value for "OriginalWeight". However, it seems that an
incorrect value is returned most of the time. Is there anything wrong
with the way I use either "break"?
Thanks!
double GetOriginalWeight ( string list, string ticker, string
side )
{
double origWeight = 0.0;
bool found = false;
foreach (BenchmarkPrice bp in mBenchmarkPriceList)
{
if ( bp.Ticker == ticker &&
bp.Side == side || ( side == "Buy" && bp.Side ==
"Cover" ) || ( side == "Sell" && bp.Side == "Short" ))
{
foreach (BMarkUnit bu in bp.AggregateLists)
{
if ( bu.ListName == list )
{
origWeight = bu.OriginalWeight;
found = true;
break;
}
}
}
if (found)
{
break;
}
}
return origWeight;
}
"mBenchmarkPriceList" is an ArrayList with each element being of
"BenchmarkPrice" type. There are three members in "BenchmarkPrice":
Ticker, Side, and AggregateLists.
The member, "AggregateLists", however, is an ArrayList with each
element being a "BMarkUnit" type. "BMarkUnit" contains two members,
ListName and OriginalWeight.
The method, "GetOriginalWeight", searches through the entire
"mBenchmarkPriceList". If a match of Ticker, Side, and also ListName
is found, it will return "OriginalWeight".
In order to be efficient, once a match is found, I "break" both loops
and return the value for "OriginalWeight". However, it seems that an
incorrect value is returned most of the time. Is there anything wrong
with the way I use either "break"?
Thanks!
double GetOriginalWeight ( string list, string ticker, string
side )
{
double origWeight = 0.0;
bool found = false;
foreach (BenchmarkPrice bp in mBenchmarkPriceList)
{
if ( bp.Ticker == ticker &&
bp.Side == side || ( side == "Buy" && bp.Side ==
"Cover" ) || ( side == "Sell" && bp.Side == "Short" ))
{
foreach (BMarkUnit bu in bp.AggregateLists)
{
if ( bu.ListName == list )
{
origWeight = bu.OriginalWeight;
found = true;
break;
}
}
}
if (found)
{
break;
}
}
return origWeight;
}