1 / 52

C#教学课件：第4章 数组.ppt

*

*

int [] num = { 12,34,67, 89};

num[0]= 33;

int i = 2 ;
num[i] = num[0] + 100 ;
*
4.3 二维数组

4.3.2

4.3.1

*
1001
76
93
68
1002
88
97
65
1109
93
86
72

4.3.1 声明二维数组

type[,] arrayName;

double [,] numbers;
int[,] stuscore = new int[3,4]; //见下表
*
1001
76
93
68
1002
88
97
65
1109
93
86
72

4.3.2 初始化二维数组

type[,] arrayName = new type[va1length,va2length] { {value1,value2},{value3,value4},{value5,value6} };
type[,] arrayName = new type[,] {{value1,value2,value3},{value4,value5,value6}};
type[,] arrayName = {{value1,value2,value3},{value4,value5,value6}};
*

1001
76
93
68
1002
88
97
65
2136
93
86
72

va1length
va2length
*
static void Main(string[] args)
{

int[,] numbers = new int[2, 3] { { 23, 44, 53 }, { 1, 100, 4 } }; //2行3列
double[,] stuscore = new double[,] { { 98, 100, 65.5 }, { 75.8, 99.5, 90 },
{ 55, 100, 64 }, { 55.5, 88.5, 99.5 } };//4行3列
string[,] bookname = { { "家", "春", "秋" }, { "雾", "雨", "电" },
{ "背影", "父亲", "童年" } }; //3行3列
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
Console.Write( bookname[i, j] );
Console.Wr

C#教学课件：第4章 数组.ppt

C#教学课件：第4章 数组.ppt