Using ??
using System;
class MainClass {
static double myMethod() {
Console.WriteLine("In myMethod().");
return 0.0;
}
public static void Main() {
double? defaultValue = 1.5;
double currentBalance;
currentBalance = defaultValue ?? myMethod();
Console.WriteLine(currentBalance);
defaultValue = null;
currentBalance = defaultValue ?? myMethod();
Console.WriteLine(currentBalance);
}
}
Output 1.5
In myMethod().
0
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
-
-
-
|