using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 二维数组
{
class Program
{
static void Main(string[] args)
{
//二维数组
int[,] str1 = new int[3, 2] {{ 1, 1 },{ 2, 2 }, { 3, 3 }};
//获取数组行数
Console.WriteLine(str1.GetLength(0));
//获取数组列数
Console.WriteLine(str1.GetLength(1));
//获取数组元素个数
Console.WriteLine(str1.Length);
Console.WriteLine("二维数组元素输出:");
for (int i = 0; i < str1.GetLength(0); i++)
{
for (int k = 0; k < str1.GetLength(1); k++)
{
if (k == str1.GetLength(1) - 1)
{
Console.WriteLine(str1[i, k].ToString());
}
else
{
Console.Write(str1[i,k].ToString() + ",");
}
}
}
//交叉数组,可以理解为其是一种特殊的一维数组,即存储一维数组的数组
int[][] str2 = new int[][] { new int[] { 1, 2, 3 }, new int[] { 1 } };
for (int i = 0; i < str2.Length; i++)
{
Console.WriteLine("交叉数组第[" + i + "]行开始输出:");
for (int k = 0; k < str2[i].Length; k++)
{
if (k == str2[i].Length - 1)
{
Console.WriteLine(str2[i][k].ToString());
}
else
{
Console.Write(str2[i][k].ToString() + ",");
}
}
}
Console.Read();
}
}
}