asp.net 動態二維數組

來源:互聯網
上載者:User

一:ArrayList存二維數組

為什麼用ArrayList?
ArrayList是動態數組,可以在不知道長度的情況下聲明和實力化,並且可以根據需要動
態增加長度,大小,刪除任意索引位置的內容.這些都是普通數組無法辦到的.

String[] get_num=new String[3];  //為了做您做例子隨意搞個可愛的數組
get_num[0]="8,5,12,12";       
get_num[1]="82,52,52,42";
get_num[2]="18,35,112,132";

        ArrayList AL=new ArrayList();   //聲明並實力化一個 傻傻的沒吃飽的ArrayList
        ArrayList AL2 = new ArrayList();//聲明並實力化一個 傻傻的沒吃飽的ArrayList

        
        for (int i=0; i < get_num.Length; i++)
        {
           String[] get_numArray= get_num[i].Split(',');           //把普通數組按照","號切開
           for (int j = 0; j < get_numArray.Length; j++)
           {
              
               AL2.Add((double)(double.Parse(get_numArray[j])));  //這個例子值預設是double類
型的把第二維的內容加到AL2中

             
           }
          
               AL.Add((double[])AL2.ToArray(typeof(double)));//把第一維的內容加到AL中
               AL2.Clear();                  //清除內容以免下一次第二維重複累積

          

        }
      
     
          double[][] get_countNum=(double[][])AL.ToArray(typeof(double[]));  //OK!他吃飽了,AL被轉
化成2維數組

 

 

自己寫的

 

if (!IsPostBack)
        {
            string[] a = Common.DealersRol().Split(new char[] { ',' });
            ArrayList Al = new ArrayList();
            ArrayList Al2 = new ArrayList();
            for (int i = 0; i < a.Length; i++)
            {
                string[] b = a[i].Split(new char[] { '|' });
                for (int j = 0; j < b.Length; j++)
                {
                    Al2.Add((string)b[j]);
                }
                Al.Add((string[])Al2.ToArray(typeof(string)));
                Al2.Clear();
            }
            string[][] c = (string[][])Al.ToArray(typeof(string[]));
            DropDownList1.DataSource = c;
            DropDownList1.DataBind();
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.