我有一个dll,它给我一个输出对象[,]
{Name = "Object[,]" FullName = "System.Object[,]"}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其转换为Object []以便能够正确读取它,因为它是一个双列对象.我试过去投了它Object[] values = (Object[])data;,但是我从tittle那里得到了错误:
Unable to cast object of type 'System.Object[,]' to type 'System.Object[]'.
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法来执行此操作?我想用它来制作一本字典.
提前致谢
而不是将它用作Object[](它不是),使用System.ArrayAPI:
var dictionary = new Dictionary<string, string>(); // For example
Array array = (Array) data;
for (int i = 0; i < array.GetLength(0); i++)
{
string key = (string) array.GetValue(i, 0);
string value = (string) array.GetValue(i, 1);
dictionary[key] = value;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5443 次 |
| 最近记录: |