请教:怎么把int[] 类型转换为 object[]
代码如下
using System;
public class EntryPoint
{
public static void Main()
{
int[] array={1,3,4,5};
object[] o=(object[])array;
}
}
编译结果:
E:\framework\test> csc test.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
test.cs(7,14): error CS0029: Cannot convert type 'int[] ' to 'object[] '
感谢
------解决方案-------------------- int[] array ={ 1, 3, 4, 5 };
object[] o = (object[])System.Collections.ArrayList.Adapter((Array)array).ToArray(typeof(object));
foreach (object oo in o)
{
Console.WriteLine(oo);
}