C#多维数组迭代 [英] C# multidimensional arrays iteration
问题描述
我是C#的新手,正在研究数组.
I'm new to C# and looking at arrays.
给出:
int[][] myJagArray = new int[5][];
以下为什么打印j(System.Int32 [])的 类型 ,而不打印每个j的内容?
Why does the following print the types of j (System.Int32[]), and not each j's contents?
foreach (int[] j in myJagArray)
{
Console.WriteLine("j : {0}",j);
}
推荐答案
因为Array.ToString()
不返回数组的内容,它返回类型名称,并且Console.WriteLine
隐式地在您发送的每个对象上调用ToString()
作为参数.
Because Array.ToString()
does not return the contents of the array, it returns the type name, and Console.WriteLine
implicitly calls ToString()
on each object you send it as a parameter.
这与数组是多维数组的一部分这一事实无关,这只是CLR开发人员选择(或更确切地说选择 not 来)实现System.Array
上.
This has no regard to the fact that the array is part of a multi-dimensional array, it is simply the way the CLR developers chose to (or rather, chose not to) implement ToString()
on System.Array
.
这篇关于C#多维数组迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!