这可能是这样的:
public static object[] untypedToObjectArray(Array arr)
{
int len = arr.Length;
object[] res = new object[len];
for(int i = 0; i < len; i++)
res[i] = arr.GetValue(i);
return res;
}
Run Code Online (Sandbox Code Playgroud)
有更好的(更高效的)方式吗?对于值类型,每个元素都需要明显加框,这可能很慢.
没有LINQ:
object[] tab = new object[input.Length];
input.CopyTo(tab, 0);
Run Code Online (Sandbox Code Playgroud)
使用LINQ:
object[] tab = input.Cast<object>().ToArray();
Run Code Online (Sandbox Code Playgroud)
"输入"是输入数组的位置.