代码:
ArrayList sines = new ArrayList( OPCClientdev.OPCClient.ht.Values);
byte[] bytes = (byte[])sines.ToArray(typeof(byte));
报错:源数组中至少有一个元素无法被向下转换到目标数组类型。
ht.values为double型数据
List<byte[]> t = new List<byte[]>();
foreach (double d in OPCClientdev.OPCClient.ht.Values)
{
t.Add(BitConverter.GetBytes(x));
}
byte[] bytes = new byte[t.Count * 8];
for (int i = 0; i < t.Count; i++)
{
bytes[i * 8] = t[i][0];
bytes[i * 8 + 1] = t[i][1];
bytes[i * 8 + 2] = t[i][2];
...
bytes[i * 8 + 7] = t[i][7];
}
byte[] bytes = OPCClientdev.OPCClient.ht.Values.OfType<double>().SelectMany(x => BitConverter.GetBytes(x)).ToArray();