I have a dll which gives me as an output an Object[,]
{Name = "Object[,]" FullName = "System.Object[,]"}
I am trying to convert it to Object[] to be able to read it properly, as it is a two columns object.
I have tried to cast it Object[] values = (Object[])data;
, but I obtained the error from the tittle:
Unable to cast object of type 'System.Object[,]' to type 'System.Object[]'.
Is there any easy way to perform this operation? I would like to make a dictionary out of it.
Thanks in advance
Rather than using it as an Object[]
(which it isn't), use the System.Array
API:
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;
}
See more on this question at Stackoverflow