c# - 格式异常 : Could not find any recognizable digits

标签 c#

我得到这个异常:

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

在这一行:

String value = "2";
uint? test = Convert.ToUInt32(value, 2);

最佳答案

那是因为你的第二个参数将基数设置为 2,而 2 不是二进制的有效数字。

来自 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.

关于c# - 格式异常 : Could not find any recognizable digits,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34059155/

相关文章:

c# - 使用 MongoDB 和 C# 将元素附加到现有项目的数组

c# - 必应语音识别服务 - SpeechClient 问题 "Audio format could not be parsed."

c# - 从 GridEX 中的行复制文本

c# - 将位图转换为图标

c# - 仅将唯一项目添加到列表

c# - 使用 ToList() 与 new List(IEnumerable<T>) 之间的性能差异

c# - 动态扩展应用程序的功能?

c# - 在运行时添加文本框并保存更改

c# - 如何在 C# 中解析没有特定标记名称的 XML

c# - Linq 选择最新的组层次结构