当前位置:网站首页>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();
}
}
边栏推荐
- puppeteer入门之 Puppeteer 类
- Use bat to write to the first line of the file
- MySQL comparison
- Use of JMeter (simulating high concurrency)
- Data consistency
- With determination to forge ahead, JASMINER continues to deepen its brand strength
- What are the ABAP keywords and syntax that cannot be used in the ABAP cloud environment?
- NGUI,冷却效果
- 数据库设计及范式讲解
- Pagoda panel backup and recovery data
猜你喜欢

UGUI

安全相关网站推荐

以银行异业合作为例,浅谈小程序生态的建设

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

为什么DDRx的电源设计时需要VTT电源

ugui图片墙

What are the functions and functions of the EMG actuator

Empire CMS imitation "game bird" template source code /92kaifa version large mobile game portal template

MySQL basic learning notes 03

Cisp-pte XSS Foundation
随机推荐
MOSFET的SOA或者ASO是什么?
Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
General idea of interface tuning
What is digital twin? A real-time and virtual representation
Explain the physical layer consistency test of 2.5g/5g/10g Base-T Ethernet interface in detail!
rpc的正确打开方式|读懂Go原生net/rpc包
UGUI
【DBSCAN】DBSCAN实例
Correct opening method of RPC | understand go native net/rpc package
UGUI
How much do you know about software compatibility testing? How to select a software compatibility testing organization?
BCGControlBar库专业版,完整记录的MFC扩展类
IPhone 15 forced to use type-C interface
Streaming computing knowledge
MySQL基础篇常用约束总结下篇
吴恩达机器学习课程-第七周
[audio and video] Introduction to SEI
MD5 learning
Wechat applet ordering system with source code
TikTok在英国遭遇文化冲突,短期内众多员工离职