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# 多维数组迭代
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
