首页 > 开发 > 综合 > 正文

C#中的数组使用

2024-07-21 02:26:33
字体:
来源:转载
供稿:网友
方法一:

string[] str = new string[2];

       str[0]  = "a";

        str[1] =  "b";

        response.write(str[0].tostring());

        response.write(str[1].tostring());

 

方法二:

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

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

        {

            response.write(str[i].tostring());

            response.write("<br>");

        }

        response.write("<br>");

 

方法三:

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

   

        response.write("<table>");

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

        {

            response.write("<tr>");

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

            {

                response.write("<td>" + str[i, x].tostring() + "</td>");

             

            }

            response.write("</tr>");

         

        }

        response.write("</table>");

方法三:

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

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

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

 

        response.write("<table>");

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

        {

            response.write("<tr>");

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

            {

                response.write("<td>" + intx[i][x].tostring() + "</td>");

 

            }

            response.write("</tr>");

 

        }

        response.write("</table>");
 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表