❔ Cleanest way to initialize string outside of conditional statement where it's assigned?
string str = ""
if(something) {
str = "a"
} else {
str = "b"
}
Is this the cleanest way? or is there a better way to expose the str outside of conditional scope without this dirty empty string initialization
5 Replies
you can just do this
Windows10CE#8553
REPL Result: Success
Result: string
Compile: 370.540ms | Execution: 34.710ms | React with ❌ to remove this embed.
var str = condition ? “This value if true” : “This value if false”;
a ternary works too in this case, I assumed you had more stuff going on in the
if
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.