This is valid and you may prefer it if you have a liking for single-liners:
int i = int.TryParse(s, out i) ? i : 42;
This sets the value of i to 42 if it cannot parse the string s, otherwise it sets i = i.
This is valid and you may prefer it if you have a liking for single-liners:
int i = int.TryParse(s, out i) ? i : 42;
This sets the value of i to 42 if it cannot parse the string s, otherwise it sets i = i.