第十九节 数组二
二维数组
int[,] Matrix = {{1,2,3},{4,,5,6},{7,8,9}};
C#中的索引是从0开始计算,因此它的第一个元素是Matrix[0,0]



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ErWei
{
class Program
{
static void Main(string[] args)
{
int[,] Max = new int[3,3] { {1,2,3},{4,5,6},{7,8,9}};
int sum = 0;
foreach (int number in Max)
{
Console.WriteLine(number);
sum += number;
}
Console.WriteLine(sum);
}
}
}
可变数组
int[][] jaggageArray = new int [2][]{new int[3]{1,2,3},new int[4]{1,2,3,4}};
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KeBian
{
class Program
{
static void Main(string[] args)
{
int[][] Kb = new int[2][] {new int[3]{1,2,3},new int[4]{1,2,3,4} };
foreach(int[] line in Kb)
{
foreach (int elment in line)
{
Console.Write(elment);
Console.Write("\n");
}
}
}
}
}
浙公网安备 33010602011771号