checking for null return for Positions.FindAll(label, Symbol)
Created at 07 Sep 2015, 19:14
checking for null return for Positions.FindAll(label, Symbol)
07 Sep 2015, 19:14
Do I need to check for null returned from Positions.FindAll(label, Symbol)?
Can I get a null ref. exception in accessing Length function on a null array (see below)?
ex:
var psns = Positions.FindAll(label, Symbol);
if(psns!=null && psns.Length>0) MyFunc()
Spotware
08 Sep 2015, 16:56
Dear Trader,
If Positions.FindAll(label, Symbol); doesn’t find any positions it returns an empty array. This means you have an array without any objects in it. In other words the array is not null but the length of the array equals to 0.
In general you don’t “need” to check whether objects are null. We highly suggest to avoid exceptions like the null reference exception.
@Spotware