I have a binary string, entered by the user, which I need to convert to an integer.
At first, I naively 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
Int32.TryParse
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…