未处理的“System.FormatException”类型的异常出现在 System.Windows.Forms.dll 中。其他信息: 输入字符串的格式不正确。
上面是异常信息,下边是报异常的代码: this.Invoke((EventHandler)(delegate
{
//判断是否是显示为16禁止
if (checkBoxHexView.Checked)
{
//依次的拼接出16进制字符串
foreach (byte b in buf)
{
builder.Append(b.ToString("X2") + " ");
}
}
else
{
//直接按ASCII规则转换成字符串
builder.Append(Encoding.ASCII.GetString(buf));
}
//追加的形式添加到文本框末端,并滚动到最后。
this.txGet.AppendText(builder.ToString());
string ReceiveText;
ReceiveText = builder.ToString();
string[] str = ReceiveText.Split(',');
foreach (string i in str) ArrText.AppendText(i.ToString()+" ");
//修改接收计数
labelGetCount.Text = "Get:" + received_count.ToString();
ArrText.AppendText("\n");
CheckSum(str,str.Length);
}));添加CheckSum()方法后就报异常,CheckSum()方法代码: private void CheckSum(string[] Checkstr,int count)
{
count=Checkstr.Length;
int num;
int[] CheckSumNum=new int[]{};
CheckSumNum = Array.ConvertAll<string, int>(Checkstr,s=>int.Parse(s));
textBox1.Text=CheckSumNum.ToString();
}
上面是异常信息,下边是报异常的代码: this.Invoke((EventHandler)(delegate
{
//判断是否是显示为16禁止
if (checkBoxHexView.Checked)
{
//依次的拼接出16进制字符串
foreach (byte b in buf)
{
builder.Append(b.ToString("X2") + " ");
}
}
else
{
//直接按ASCII规则转换成字符串
builder.Append(Encoding.ASCII.GetString(buf));
}
//追加的形式添加到文本框末端,并滚动到最后。
this.txGet.AppendText(builder.ToString());
string ReceiveText;
ReceiveText = builder.ToString();
string[] str = ReceiveText.Split(',');
foreach (string i in str) ArrText.AppendText(i.ToString()+" ");
//修改接收计数
labelGetCount.Text = "Get:" + received_count.ToString();
ArrText.AppendText("\n");
CheckSum(str,str.Length);
}));添加CheckSum()方法后就报异常,CheckSum()方法代码: private void CheckSum(string[] Checkstr,int count)
{
count=Checkstr.Length;
int num;
int[] CheckSumNum=new int[]{};
CheckSumNum = Array.ConvertAll<string, int>(Checkstr,s=>int.Parse(s));
textBox1.Text=CheckSumNum.ToString();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货