checking for null return for Positions.FindAll(label, Symbol)

Created at 07 Sep 2015, 19:14
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
aharonzbaida's avatar

aharonzbaida

Joined 01.01.2015

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()


@aharonzbaida
Replies

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

aharonzbaida
08 Sep 2015, 18:39

Thanks


@aharonzbaida