What is the convert.ToString equivalent of the variable.ToString() in this scenario?

they used variable.ToString() in this instance which makes sense, but say the value was null so you would have to use convert.ToString, so then how would u format Convert.ToString(variable) into currency or 3dp? Just need a bit of help with what the code would be. Thanks
9 Replies
Jimmacle
Jimmacle2y ago
i have never used Convert.ToString for anything why not just nullcheck? variable?.ToString("format") ?? "text if null"
TheIronDisciple
TheIronDiscipleOP2y ago
I'm new to coding, does that just avoid the null exception?
jcotton42
jcotton422y ago
yes
TheIronDisciple
TheIronDiscipleOP2y ago
the error thing if its null ah ok
jcotton42
jcotton422y ago
?. is conditional access
TheIronDisciple
TheIronDiscipleOP2y ago
i see, thanks
jcotton42
jcotton422y ago
and ?? is null coalescing
Jimmacle
Jimmacle2y ago
it's shorthand for checking if the variable is null before accessing a member of it, and if it is it short-circuits the whole expression to return null then ?? is "if the left hand side is null return the right hand side, otherwise return the left hand side"
TheIronDisciple
TheIronDiscipleOP2y ago
that makes sense, thanks guys :)
Want results from more Discord servers?
Add your server