C# multidimensional arrays iteration(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# 多维数组迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 多维数组迭代


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01