html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

C#中的数组使用_.NET教程_编程技术

[ ] 已经帮助:人解决问题
数组
方法一:

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>");
 
bRSHTML5中文学习网 - HTML5先行者学习网
bRSHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助