假设我有一个对象数组
int[] addOns = new int[] { 2, 4, 0, 4};
string[] pizzSize = new string[] {"Large","Medium","Small"};
Object[] Pizza = new object[] { 1, "Hello", 2.4, 'c' , addOns, pizzSize};
我想一张一张地打印它们,但是如果元素是数组,那么我必须做一个嵌套循环,例如这样的
foreach (object element in Pizza)
{
if (isArray(element))
{
foreach (object moreItems in element)
{
Console.WriteLine(moreItems);
}
}
else
{
Console.WriteLine(element);
}
}
这个问题曾经被问过,但没有给出答案