当前位置:网站首页>C#入门系列(十一) -- 多维数组
C#入门系列(十一) -- 多维数组
2022-06-11 10:23:00 【InfoQ】
int[,] arr = new int[,]{{1,2,3},{4,5,6},{7,8,9}};int[,] arr = {{1,2,3},{4,5,6},{7,8,9}};class Program{
static void Main(string[] args){
int[,] arr = new int[,] { { 1, 2 }, { 3, 4 } };
// 遍历行
for (int i = 0; i < arr.GetLength(0); i++)
{
// 遍历列
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.WriteLine(arr[i,j]);
}
}
// foreach遍历
foreach (var item in arr)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}int[][]Arr = new int[3][];Arr[0] = new int[] { 1, 2, 3 };Arr[1] = new int[] { 4, 5, 6, 7 };Arr[2] = new int[] { 8, 8 };class Program{
static void Main(string[] args){
int[][]Arr = new int[3][];
Arr[0] = new int[] { 1, 2, 3 };
Arr[1] = new int[] { 4, 5, 6, 7 };
Arr[2] = new int[] { 8, 8 };
// 取维度长度
for (int i = 0; i < Arr.GetLength(0); i++)
{
// 注意是这里是Arr[i].GetLength(0),
for (int j = 0; j < Arr[i].GetLength(0); j++)
{
Console.WriteLine(Arr[i][j]);
}
}
// foreach遍历
foreach (var item in Arr)
{
Console.WriteLine(item);
// 输出System.Int32[],取不到具体值
}
Console.ReadLine();
}
}
边栏推荐
- Excellent test engineer must have 4 safety test methods!
- Xilinx pin constraint file xdc
- EMC rectification cases of electronic equipment radiation
- MySQL transaction
- Correct opening method of RPC | understand go native net/rpc package
- [Objective-C] dynamically create controls
- Initial deployment of Servlet
- Mysql-- index
- Finite cyclic group
- 利用PHP开发的一款万能、表白墙系统部分代码片段
猜你喜欢

Can station B make money?
![[machine learning theory] true positive, true negative, false positive, false negative concept](/img/59/8264d6cbd96480b59e5b8ff96320be.png)
[machine learning theory] true positive, true negative, false positive, false negative concept

选择DC-DC开关电源控制器的实战过程

Q1营收超华尔街预期,挚文集团的价值等待回归

Reprint: linearlayout+fragment to achieve the lower navigation bar effect

详解2.5G/5G/10G Base-T以太网接口物理层一致性测试!

Cisp-pte XSS Foundation

Cas de rectification du CEM rayonné par des équipements électroniques

Internet of things security in the era of remote work

Mysql--索引
随机推荐
FPGA infrastructure [reference ug998]
【bert】:在训练bert 语义相似的任务时,last ave state 的计算
Dimension types for different CV tasks
Start jar
What are the differences between Parker pilot solenoid valve and direct acting solenoid valve?
以银行异业合作为例,浅谈小程序生态的建设
minIni移植到littlefs
Explain the physical layer consistency test of 2.5g/5g/10g Base-T Ethernet interface in detail!
Function and function of wandfluh proportional valve
Q1营收超华尔街预期,挚文集团的价值等待回归
iPhone 15 被迫用上 Type-C 接口
UGUI
Mouse click coordinate transformation generation
Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
rpc的正确打开方式|读懂Go原生net/rpc包
Detailed explanation of Lora module wireless transceiver communication technology
使用bat向文件的第一行中写入内容
[high concurrency] the interviewer of ant financial asked me about thread pool!!
Reprint: linearlayout+fragment to achieve the lower navigation bar effect
After four years of outsourcing, it was abandoned