I want to convert a value entered in a textBox (which can only be empty or “1” or “2” or “3”) to an integer. If empty I want it to be 0, otherwise, it’s corresponding value (1, 2, or 3).
Is there a way to do that like:
MyIntVal = TryConvertToInt(textBox1.Text, 0);
…where an empty string or anything not readily convertible to an int would default to 0?
Will default to 0 if stringValue cannot be parsed to an int.
http://msdn.microsoft.com/en-us/library/f02979c7.aspx