当前位置:网站首页>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();
}
}
边栏推荐
- What hydraulic oil is used for Denison hydraulic pump? What are the requirements
- Interview review - closure
- 详述用网络分析仪测量DC-DC和PDN
- NGUI,飘血
- Introduction to steamvr
- Bcgcontrolbar Library Professional Edition, fully documented MFC extension class
- [Objective-C] dynamically create controls
- DOtween使用方法
- NGUI,冷却效果
- With determination to forge ahead, JASMINER continues to deepen its brand strength
猜你喜欢

Dynamically render data and carousels

UGUI

Can station B make money?

Internet of things security in the era of remote work

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

How much do you know about the functions and functions of Rexroth solenoid directional valve

UGUI

Introduction to ZigBee module wireless transmission star topology networking structure

Secret behind the chart | explanation of technical indicators: tangqi'an channel

Mysql--事务
随机推荐
【DBSCAN】DBSCAN实例
RSA signature issues
Habitable planet
About CI framework batch export to compressed file
Browserfetcher class for getting started with puppeter
puppeteer入门之 BrowserFetcher 类
Waiting event enq: Ko - some feasible processing methods for fast object checkpoint
Correct opening method of RPC | understand go native net/rpc package
以银行异业合作为例,浅谈小程序生态的建设
[high concurrency] the interviewer of ant financial asked me about thread pool!!
Use of JMeter (simulating high concurrency)
MySQL comparison
Picture rule page turning
MySQL基础篇常用约束总结上篇
Unity字体间距
What are the functions and applications of Mogg test controller
rpc的正确打开方式|读懂Go原生net/rpc包
Q1's revenue exceeded Wall Street's expectations, and the value of Zhiwen group is waiting to return
Pyramidtnt: TNT with characteristic pyramid structure
rpc的正确打开方式|读懂Go原生net/rpc包