-3

不知何故,这似乎在几年前起作用了;)或者我错过了什么?

帮助将提前获得。

else if (recStatus == 3)         
{
            ((TextBox)rref[1]).Text = read;

            //string readData = read;
            string[] readData = read.Split(new Char[] { ',' });


            //string[] readdata = read.Split(',');
            txtType.Text = readData[0];
            txtSerno.Text = readData[1]
            txtFirmware.Text = readData[2] + "." + readData[3];
}
4

2 回答 2

1

此代码中的 System.IndexOutOfRangeException 意味着 readData 的值小于 4,

你可以知道元素的数量

string[] readData = read.Split(new Char[] { ',' });
MessageBox.Show(readData.Length.ToString()); //you will found it less then 4
于 2013-02-22T15:00:25.850 回答
0

我刚刚运行了您的示例,并且在控制台应用程序中没有出现错误(这可能是因为您传递的文本放置了一个调试器并查看 ((TextBox)rref[1]).Text 上的实际文本 ):

class Program
    {
        static void Main(string[] args)
        {
            string read = "A401,192,2,8" ;

            string[] readData = read.Split(new Char[] { ',' });


            //string[] readdata = read.Split(',');
            string a = readData[0];
            string b = readData[1] + "." + readData[2];
            string c = readData[3];

            Console.WriteLine(a + b + c);
        }
    }

结果 :

A401192.28
Press any key to continue . . .
于 2013-02-22T15:10:13.917 回答