Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c语言中的十进制到十六进制“带错误”;类型为';的未处理异常;System.FormatException';发生在mscorlib.dll中;_C#_Hex_Decimal - Fatal编程技术网

C# c语言中的十进制到十六进制“带错误”;类型为';的未处理异常;System.FormatException';发生在mscorlib.dll中;

C# c语言中的十进制到十六进制“带错误”;类型为';的未处理异常;System.FormatException';发生在mscorlib.dll中;,c#,hex,decimal,C#,Hex,Decimal,我的代码非常简单: string aveint = "aveint"; otdr_Portobject.WriteLine(aveint +int_averagesCon.Value.ToString("X2")+ "\n"); otdr\u Portobject是一个COM端口 int\u averagesCon是一个值为64的数字向上向下 当我运行程序时,总会有一个消息框显示: mscorlib.dll中发生类型为“System.FormatException”的未处理异常 有人知道我为什

我的代码非常简单:

string aveint = "aveint";
otdr_Portobject.WriteLine(aveint +int_averagesCon.Value.ToString("X2")+ "\n");
otdr\u Portobject
是一个COM端口

int\u averagesCon
是一个值为64的数字向上向下

当我运行程序时,总会有一个消息框显示:

mscorlib.dll中发生类型为“System.FormatException”的未处理异常

有人知道我为什么一直出现此错误吗?

指定的“X2”格式仅受整型支持

NumericUpDown。值为十进制

您需要首先将十进制值转换为整数类型,例如:

Convert.ToInt32(int_averagesCon.Value).ToString("X2")+ ...
指定的“X2”格式仅受整型支持

NumericUpDown。值为十进制

您需要首先将十进制值转换为整数类型,例如:

Convert.ToInt32(int_averagesCon.Value).ToString("X2")+ ...
指定的“X2”格式仅受整型支持

NumericUpDown。值为十进制

您需要首先将十进制值转换为整数类型,例如:

Convert.ToInt32(int_averagesCon.Value).ToString("X2")+ ...
指定的“X2”格式仅受整型支持

NumericUpDown。值为十进制

您需要首先将十进制值转换为整数类型,例如:

Convert.ToInt32(int_averagesCon.Value).ToString("X2")+ ...
试试这个

otdr_Portobject.WriteLine(aveint +((byte)int_averagesCon.Value).ToString("X2")+ "\n");
这将首先从
double
创建一个
byte
值,然后尝试格式化

otdr_Portobject.WriteLine(aveint +((byte)int_averagesCon.Value).ToString("X2")+ "\n");
这将首先从
double
创建一个
byte
值,然后尝试格式化

otdr_Portobject.WriteLine(aveint +((byte)int_averagesCon.Value).ToString("X2")+ "\n");
这将首先从
double
创建一个
byte
值,然后尝试格式化

otdr_Portobject.WriteLine(aveint +((byte)int_averagesCon.Value).ToString("X2")+ "\n");
这将首先从
double
创建一个
byte
值,然后尝试格式化。

您不能将X2(二进制格式)与十进制类型一起使用

简单的解决方案是将十进制转换为整数,并调用字符串

decimal x = 64;
((int)x).ToString("X2");
不能将X2(二进制格式)与十进制类型一起使用

简单的解决方案是将十进制转换为整数,并调用字符串

decimal x = 64;
((int)x).ToString("X2");
不能将X2(二进制格式)与十进制类型一起使用

简单的解决方案是将十进制转换为整数,并调用字符串

decimal x = 64;
((int)x).ToString("X2");
不能将X2(二进制格式)与十进制类型一起使用

简单的解决方案是将十进制转换为整数,并调用字符串

decimal x = 64;
((int)x).ToString("X2");

哪个是异常的堆栈跟踪?哪个是异常的堆栈跟踪?哪个是异常的堆栈跟踪?哪个是异常的堆栈跟踪?