c#无法强制转换类型为'的对象;system.int16[*]和#x27;输入';system.Int16[]和#x27;
我正在从plc标签读取值c#无法强制转换类型为'的对象;system.int16[*]和#x27;输入';system.Int16[]和#x27;,c#,opc,C#,Opc,我正在从plc标签读取值 public void synch_read() //reads device { Array values; Array errors; object qualities = new object(); //opc server will store the quality of the item object timestamps = new object(); //store the timestamp of the read
public void synch_read() //reads device
{
Array values;
Array errors;
object qualities = new object(); //opc server will store the quality of the item
object timestamps = new object(); //store the timestamp of the read
//read directly from device
oGroup.SyncRead((short)OPCAutomation.OPCDataSource.OPCDevice, 2, ref handles, out values, out errors, out qualities, out timestamps);
String abcd = (Int16[])qualities.ToString();
}
在这一行
String abcd = ((Int16[])qualities).ToString();
我发现了错误
unable to cast object of type 'system.int16[*]' to type 'system.Int16[]'
如何解决此错误
编辑
我试过了
Int16[] abcd = (Int16[2])qualities;
错误
;应为系统。int16[*]
是多维数组,而不是一维数组
Array array = (Array)qualities;
int dimensions = array.Rank;
如果dimensions
为2,则它是int[,]
。如果是3,则为int[,]
,依此类推
有关使用foreach
迭代数组的信息,请参见系统的示例。int16[*]
是多维数组,而不是一维数组
Array array = (Array)qualities;
int dimensions = array.Rank;
如果dimensions
为2,则它是int[,]
。如果是3,则为int[,]
,依此类推
要使用foreach
迭代数组,请参见示例您将强制转换为字符串,然后是Int16[]
,然后将该值分配给字符串???((Int16[])。ToString()
也会给出相同的错误@CarbineCoder,dynamic
库不存在您正在强制转换为字符串,然后是Int16[]
然后将该值分配给字符串???((Int16[])。ToString()
也会给出相同的错误@卡宾编码器,动态
库不存在