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
Jimmacle6mo 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 chatgpt6mo ago
SOLVED
Jimmacle
Jimmacle6mo ago
$close
MODiX
MODiX6mo ago
Use the /close command to mark a forum thread as answered
i like chatgpt
i like chatgpt6mo ago
$close
MODiX
MODiX6mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server
More Posts
✅ Can't modify a list outside of the cycleSo I'm trying to modify differenceList in a cycle, but it gives me an error (see attachment), althouClass Naming ConventionsI'm currently renaming all the classes in my Discord Bot project but I'm stumped to decide what the ✅ [AVALONIA] Get all coordinates along a PolylineWhilst you define the points for a Polyline, is there any way that I can get or calculate the rest oCleaner NavigationView implementation (Avalonia)I'm currently porting an existing project that i didn't write from WinUI3 to Avalonia. The project Iprogram closing early```cs Console.WriteLine("What was the digital portfolio mark (out of 35)?"); int dpMark = int.Parse(Fully stuck on making a clickable game object system in unityim fully stuck right now, I cant find a good solution for this problem, so basically im making a gam✅ [AVALONIA] Return Coordinates (Only if a Polyline is present in those coordinates)Ive completed my A* Pathfinding but need to dump alot of uneccesary coordinates from the created grineed some help understanding configuration comming from "Environment Variables"so I read some docs that says I should store secrts for development using the Secrets.json service. ✅ Return Coordinates (Only if a Polyline is present in those coordinates)Ive completed my A* Pathfinding but need to dump alot of uneccesary coordinates from the created griI need help debugging c# event-based reliable UDP implementation.Note: I know that there are libraries that can do this and even more. But for my own reasons, I want