[英]c# unable to cast object of type 'system.int16[*]' to type 'system.Int16[]'
I am reading the values from plc tags 我正在读取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
//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();
}
In this line 在这条线
String abcd = ((Int16[])qualities).ToString();
I am getting the error 我收到错误
unable to cast object of type 'system.int16[*]' to type 'system.Int16[]'
How can I solve this error? 我该如何解决这个错误?
EDIT 编辑
I tried 我试过了
Int16[] abcd = (Int16[2])qualities;
error ; expected
错误; expected
; expected
The system.int16[*]
is a multidimensional array, not a single dimensional array. system.int16[*]
是一个多维数组,而不是一维数组。
Array array = (Array)qualities;
int dimensions = array.Rank;
If dimensions
is 2, then it is a int[,]
. 如果dimensions
为2,则为int[,]
。 If it is 3 it is int[,,]
and so on. 如果为3,则为int[,,]
,依此类推。
For iterating the array with foreach
see for example https://stackoverflow.com/a/2893367/613130 要使用foreach
迭代数组,请参见例如https://stackoverflow.com/a/2893367/613130
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.