红联Linux门户
Linux帮助

C#中的数组使用

发布时间:2006-08-28 09:58:54来源:红联作者:phpjava
方法一:

[code]string[] str = new string[2];

str[0] = "a";

str[1] = "b";

Response.Write(str[0].ToString());

Response.Write(str[1].ToString());[/code]

方法二:

[code] string[] str = new string[] { "x", "xx", "xxx" };

for (int i = 0; i < str.Length; i++)

{

Response.Write(str[i].ToString());

Response.Write("
");

}

Response.Write("
");[/code]

方法三:

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

Response.Write("");

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

{

Response.Write("");

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

{

Response.Write("");



}

Response.Write("");



}

Response.Write("
" + str[i, x].ToString() + "
");[/code]

方法三:

[code]int[][] intx = new int[2][];

intx[0] = new int[] { 1, 2, 3, 4 };

intx[1] = new int[] { 5, 6, 7, 8 };



Response.Write("");

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

{

Response.Write("");

for (int x = 0; x < 4; x++)

{

Response.Write("");



}

Response.Write("");



}

Response.Write("
" + intx[i][x].ToString() + "
");[/code]
文章评论

共有 1 条评论

  1. rabbitonly 于 2006-08-31 17:39:04发表:

    指mono中么?