在VB.NET下成功运行!! 但是转到C#上就出问题了!!
原因在于VB中有一段代码在C#中找不到相对应的代码代替
VB代码如下:
Dim SendValue(7) As Byte
Dim SendValuet(5) As Byte
Dim datavalue() As Byte
Dim Addr As Short
Dim CRC() As Byte
On Error Resume Next
        Addr = 1
        SendValuet(0) = &H1S '地址
        SendValuet(1) = &H3S
        SendValuet(2) = &H0S
        SendValuet(3) = &H0S
        SendValuet(4) = &H0S
        SendValuet(5) = &H4S        CRC = System.Text.UnicodeEncoding.Unicode.GetBytes(CRCcheck(SendValuet)) '暂时假设CRCcheck这个函数我移植正确
        
        SendValue(0) = SendValuet(0)
 
        SendValue(1) = SendValuet(1)
        SendValue(2) = SendValuet(2)
        SendValue(3) = SendValuet(3)
        SendValue(4) = SendValuet(4)
        SendValue(5) = SendValuet(5)
        SendValue(6) = CRC(1)
        SendValue(7) = CRC(0)       MSComm1.Output = VB6.CopyArray(SendValue)
       datavalue = MSComm1.Input
       oitem(1).Write(datavalue(3) * 256 + datavalue(4))'oitem是OPC对象转化成C#的代码如下:
byte[] SendValue = new byte[8];
byte[] SendValuet = new byte[6];
byte[] datavalue;
short Addr;
byte[] CRC;      Addr = 1;
      SendValuet[0] = 0x1; //地址      SendValuet[1] = 0x3;
      SendValuet[2] = 0x0;
      SendValuet[3] = 0x0;
      SendValuet[4] = 0x0;
      SendValuet[5] = 0x4;      CRC = System.Text.UnicodeEncoding.Unicode.GetBytes(Module1.CRCcheck(SendValuet)); // 暂时假设CRCcheck这个函数我移植正确
      SendValue[0] = SendValuet[0];
      SendValue[1] = SendValuet[1];
      SendValue[2] = SendValuet[2];
      SendValue[3] = SendValuet[3];
      SendValue[4] = SendValuet[4];
      SendValue[5] = SendValuet[5];
 
      SendValue[6] = CRC[1];
 
      SendValue[7] = CRC[0];
      
      MSComm1.Output = Microsoft.VisualBasic.Compatibility.VB6.Support.CopyArray(SendValue);      
      datavalue = (byte[])MSComm1.Input;      oitem[1].Write(datavalue[3] * 256 + datavalue[4]);//oitem是OPC对象在执行temp = datavalue[3] * 256 + datavalue[4];  这行代码的时候
提示出错信息是“索引超出了数组界限。”  我找到了问题的根源就是VB中有一段 On Error Resume Next , 而在C#中我找不到相对应的代码取代,如果在VB中去掉这句,同样也会出现数组超出界限提示。
请问在C#中怎么把VB中这个 On Error Resume Next移植过来???PS:说一下我这段程序是做什么的,就是设备寄存器的值通过这段程序处理传给AxMSComm对象,然后利用AxMSComm对象将数据写到传送给OPC服务器。oitem是OPC的一个对象。