您的位置:首页 > 其它

一维整型字符串数组、二维数组、锯齿数组

2015-09-01 15:43 253 查看
class Program

{

static void Main(string[] args)

{

//整数一维数组赋值的三种方法

int[] a = { 1, 2, 3, 4, 5, 6 }; //静态赋值

int[] b = new int [6] ;//动态赋值

int[] c = new int [6] { 1, 2, 3, 4, 5, 6 };

int[] d = new int[] { 1, 2, 3, 4, 5, 6 };

//字符串数组赋值的方法

string[] array = new string[5] { "bob", "jone", "joshua", "make", "jeson" };

/*for (int i = 0; i < 5; i++) {

Console.WriteLine(array[i]);

Console.ReadKey();

}*/

foreach (string f in array) { //遍历数组

Console.WriteLine(f);

}

//数字二维数组的赋值方法

int[,] erweri1 = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };

/*for (int i = 0; i < 3; i++)

{

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

{

Console.WriteLine(erweri1[i, j]);

}

}*/

foreach (int g in erweri1) {

Console.WriteLine(g);

}

//数组的数组,锯齿数组

int[][] arr2 = {new int[]{1,2,3},new int[]{4,5},new int[]{6},new int[]{7,8,9}};

int[][] arr = new int[10][];

for (int i = 0; i < arr.GetLength(0); i++)

{

arr[i] = new int[i + 1];

}

arr[0][0] = 1;

for (int i = 1; i < arr.GetLength(0); i++)

{

for (int j = 0; j < i; j++)

{

arr[i][j + 1] = arr[i - 1][j];

arr[i][j] = arr[i][j] + arr[i - 1][j];

}

}

char c1 = ' ';

for (int i = 0; i < 10; i++)

{

for (int k = 10 - i; k > 0; k--)

{

Console.Write("{0}", c1);

}

for (int j = 0; j < i + 1; j++)

{

Console.Write(" {0}", arr[i][j]);

}

Console.WriteLine();

}

Console.ReadKey();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: