Ошибка 2 Аргумент "1": преобразование типа из "int[]" в "object[]" невозможно - C#
Формулировка задачи:
object - базовый класс для int. Тогда почему невозможно преобразовать int[] в object[]?
//using System;
namespace Liberti
{
class Tester
{
public static void PrintMyArray(object[] theArray)
{
foreach (object obj in theArray)
System.Console.Write("{0} ", obj);
System.Console.WriteLine();
}
static int Main()
{
int[] myArray = {5,4,6,7};
PrintMyArray(myArray);
return 0;
}
}
}Решение задачи: «Ошибка 2 Аргумент "1": преобразование типа из "int[]" в "object[]" невозможно»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication73
{
class Program
{
public static void PrintMyArray(object[] theArray)
{
foreach (object obj in (int[])theArray[0])
System.Console.Write("{0} ", obj);
System.Console.WriteLine();
}
static int Main()
{
int[] myArray = { 5, 4, 6, 7 };
PrintMyArray(new Object[]{myArray});
Console.ReadLine();
return 0;
}
}
}