当前位置:网站首页>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();
}
}
边栏推荐
- Some understanding of inductive bias
- Mouse click coordinate transformation generation
- Introduction to ZigBee module wireless transmission star topology networking structure
- TikTok在英国遭遇文化冲突,短期内众多员工离职
- What are the ABAP keywords and syntax that cannot be used in the ABAP cloud environment?
- Tree topology networking structure of ZigBee module communication protocol
- 数据库设计及范式讲解
- Introduction to steamvr
- Tiktok encounters cultural conflict in the UK, and many employees leave in a short time
- Technology cloud report: privacy computing under the wave of Web3.0
猜你喜欢
随机推荐
Secret behind the chart | explanation of technical indicators: tangqi'an channel
C+ daily exercises (15)
[machine learning theory] true positive, true negative, false positive, false negative concept
Installing mysql5.7 for Linux
Jedislock redis distributed lock implementation
数据库设计及范式讲解
[high concurrency] the interviewer of ant financial asked me about thread pool!!
Mysql-- index
[Objective-C] dynamically create controls
【机器学习理论】True Positive, True Negative, False Positive, False Negative概念
Use bat to write to the first line of the file
LoRa模块无线收发通信技术详解
MD5 learning
Beginning simple blog emlog theme template V3
面试复习之---闭包
使用bat向文件的第一行中写入内容
1. system in Library
Differences between beanfactory and factorybean
Mysql--索引
iPhone 15 被迫用上 Type-C 接口








