Difference between double? and double variable

Created at 15 Jan 2016, 09:55
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!
ozan's avatar

ozan

Joined 07.11.2015

Difference between double? and double variable
15 Jan 2016, 09:55


@ /api/reference/robot/modifypositionasync

a double? variable is used.

What is the difference between double? and regular double variable?

Can a double? variable take null value?

Is this expression correct?

double? stopLoss = null;

double? takeProfit = null;

ModifyPositionAsync (position, stopLoss, takeProfit);

Thanks in advance.

Best regards.

 

public TradeOperation ModifyPositionAsync(Position position, double? stopLoss, double? takeProfit, [optional] Action callback)
var position = Positions.Find("myLabel", Symbol, TradeType.Buy);
if (position != null)
{
    double? stopLoss = Symbol.Ask- 10*Symbol.PipSize;
    double? takeProfit = Symbol.Ask + 10 * Symbol.PipSize;
    ModifyPositionAsync(position, stopLoss,  takeProfit);
}

@ozan
Replies

ozan
15 Jan 2016, 10:44

found the answer @ http://stackoverflow.com/questions/15491889/how-to-assign-null-value-to-non-nullable-type-variable-in-c

How to assign Null value to Non-Nullable type variable in C#?

You have to declare it as a nullable type:

double? x;
x = null;

Non nullable types like double can not be null

 


@ozan