当前位置: 代码迷 >> 综合 >> c#交错数组
  详细解决方案

c#交错数组

热度:31   发布时间:2023-09-27 14:26:36.0

交错数组是数组的数组,可以声明一个带有int值的交错数组scores

int [] [] scores;

声明一个数组不会在内存中创建数组,创建上面的数组

int [] [] scores=new int [5][];

for (int i=0;i<scores.length;i++)

{

scores[i]=new int [4];

}


初始化交错数组

int [] [] scores=new int [2][]{new int []{92,93,94},new int []{85,86,87,88}};

其中,scores是一个由两个整型数组组成的数组--scores[0]是一个带有三个整数的数组,scores[1]是一个带有4个整数的数组

using System;

namespace ArrayApplication

{

class MyArray

{

static void Main(string [] args)

{

int [] [] a=new int [] []{new int [][]{0,0},new int [] {1,2},new int[] {2,4},new int []{3,6},new int []{4,8}};

int i.j;

for(i=0;i<5;i++)

{

for(j=0;j<2;j++)

{

Console.WriteLine("a[{0}][{1}]={2}",i,j,a[i][j]);

}

}

Console.ReadKey();

}

}

}

  相关解决方案