I have the following code:
if (question.DetailsJSON != null) {
var details = JSON.FromJSONString<List<Question.Detail>>(question.DetailsJSON);
}
This works but outside of the block the details is not available.
Without pre-declaring the details variable is there a way that I could do this if test and still have details available once outside of the if ?
You can combine the declaration and initialization, and use a conditional operator to avoid introducing a new scope with the
ifstatement: