今天主要学习了C#中的二维数组。
二维数组的声明方式:
using System;
namespace test4
{
class Program
{
static void Main(string[] args)
{
//二维数组的声明
int[,] b = new int[2, 3] { { 1, 2, 3 },
{ 4, 5, 6 } };
for (int i = 0; i < b.GetLength(0); i++)
{
for (int j = 0; j < b.GetLength(1); j++)
{
Console.Write(b[i, j]);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
交错数组
//交错数组声明方式 int[][] str = new int[3][]; str[0] = new int[3] { 1, 2, 3 }; str[1] = new int[] { 1, 2 }; str[2] = new int[] { 1, 2, 3, 4 }; for (int i = 0; i < str.Length; i++) { for (int j = 0; j < str[i].Length; j++) { Console.Write(str[i][j]); } Console.WriteLine(); }