class Program
{
static void Main(string[] args)
{
int[] array = { 1, 2, 3, 4 };
int[][] newArray = { new int[] { 1, 3, 4, 5, 6 }, new int[] { 2, 4, 6, 8, 2 } };            //动态初始化
int[,] csharpArray = new int[3, 5];
int[,] maps = new int[,] { {3,5},{1,2},{2,4} };
Console.WriteLine(maps[2, 1]);
//获取⼆维数组的长度,相当于⼆维数组的元素个数(总长度)
Console.WriteLine(maps.Length);
/
/如何获取⼆维数组的长度
Console.WriteLine("0:" + maps.GetLength(0));
Console.WriteLine("1:" + maps.GetLength(1));
//⼆维数组的遍历
int[,] heroData = {
{3,0,0},
{0,5,0},
{1,0,2},
{0,1,3}
};
for (int i = 0; i < heroData.GetLength(0); i++) {
for (int j = 0; j < heroData.GetLength(1); j++) {
Console.Write(heroData[i, j]+"\t");
}
//换⾏
Console.WriteLine();
}
}
}
}
namespace TestForeach
{
class Program
{
static void Main(string[] args)
{
int[] number = { 3, 5, 7, 9 };
foreach (var item in number)
{
Console.WriteLine(item);
二维数组下标怎么理解}
}
}
}
底层消耗⽐for循环⾼
using System;
namespace TestForeach
{
class Program
{
static void Main(string[] args)
{
int[] number = { 3, 5, 7, 9 };
foreach (var item in number)
{
Console.WriteLine(item);
}
int[,] map = { { 0, 0, 0 }, { 1, 0, 3 }, { 5, 0, 8 }, { -1, 0, -2 } };
Console.WriteLine("foreach遍历⼆维数组");
foreach (var item in map) { Console.WriteLine(item); }
Console.WriteLine("foreach遍历string");
string str = "Hello,Unity!";
foreach (var item in str) {
Console.WriteLine(item);
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。