Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FormatException: Could not find any recognizable digits

Tags:

c#

I get this exception:

A first chance exception of type 'System.FormatException' occurred in mscorlib.dll

At this line:

String value = "2";
uint? test = Convert.ToUInt32(value, 2);
like image 880
Philies Avatar asked Dec 03 '15 06:12

Philies


1 Answers

That's because your second parameter sets the base to 2, and 2 is not a valid digit in binary.

From MSDN

The call to public static uint ToUInt32(string value, int fromBase) will throw a FormatException when value contains a character that is not a valid digit in the base specified by fromBase. The exception message indicates that there are no digits to convert if the first character in value is invalid; otherwise, the message indicates that value contains invalid trailing characters.

like image 164
shree.pat18 Avatar answered Oct 23 '22 07:10

shree.pat18