Can these ternary expression with expensive method calls be simplified without outline variables ...

I do NOT want to - call expensive methods more than once. - make "outline" temporary variables. Outline variables are ones declared outside ternary expressions. - leak variables with letters.
var out1 = ExpensiveMethod1(x, y) is bool __ ? __.ToString() : "null";
var out2 = ExpensiveMethod2(x, y) is bool ___ ? ___.ToString() : "null";
var out3 = ExpensiveMethod3(x, y) is bool ____ ? ____.ToString() : "null";
var out1 = ExpensiveMethod1(x, y) is bool __ ? __.ToString() : "null";
var out2 = ExpensiveMethod2(x, y) is bool ___ ? ___.ToString() : "null";
var out3 = ExpensiveMethod3(x, y) is bool ____ ? ____.ToString() : "null";
where bool? ExpensiveMethod*<T,U>(T t, U u){}. Can these expression be simplified even further?
6 Replies
Jimmacle
Jimmacle11mo ago
not enough information what do those methods return? conditional access operator and null coalescing operator var out1 = ExpensiveMethod1(x, y)?.ToString() ?? "null";
i like chatgpt
i like chatgptOP11mo ago
SOLVED
Jimmacle
Jimmacle11mo ago
$close
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered
i like chatgpt
i like chatgptOP11mo ago
$close
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server