In that case, I would usually use nullas indicated in the comment. Thus, the code will look like this:
public void DoSomething(int a, int? bOverwrite = null)
{
int b = bOverwrite ?? 42;
}
In this case, you usually delete the variable parameterIsSetand initialize the variable with zero and, if necessary, set the value:
int? myB = null;
if ()
{
myB = 29;
}
DoSomething(a, myB);
parameterIsSet, :
DoSomething(a, parameterIsSet ? b : default(int?));
:
, :
class DoSomethingParameters
{
public DoSomethingParameters() { A = 12; B = 42; }
public int A { get; set; }
public int B { get; set; }
}
var parameters = new DoSomethingParameters();
parameters.A = ;
if ( {
parameters.B = 29;
}
DoSomething(parameters);
IF , b , , , .
if ()
{
int b = some_complet_expression;
DoSomething(a, b);
}
else
{
DoSomething(a);
}
, , , . . , .