Hello,
I have a binary string, entered by the user, which I need to convert to an integer.
At first I naivly used this simple line:
Convert.ToInt32("11011",2);
Unfortunately this throws an exception if the user enters the integer directly.
Convert.ToInt32("123",2); // throws Exception
How can I make sure that the string entered by the user actually is a binary string?
- try..catch....but that's just too ugly.
- something like 'Int32.TryParse' maybe.
Thanks