C# 多维数组迭代 [英] C# multidimensional arrays iteration

查看:25
本文介绍了C# 多维数组迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 C# 新手,正在研究数组.

I'm new to C# and looking at arrays.

给定:

int[][] myJagArray = new int[5][];

为什么下面会打印 j (System.Int32[]) 的 types,而不是每个 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 开发人员选择(或者更确切地说,选择来)实现 ToString()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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆