stuff ArrayList inside ArrayList or use DataTable

解决方案 »

  1.   

    用此方法可在ArrayList中添加任何类型的数据
    class Inventory
    {
    string one,two;
    public Inventory(string s1,string s2)
    {
    one=s1;
    two=s2;
    }
    public string toone()
    {
    return one;
    }
    public string totwo()
    {
    return two;
    }
    }
    class InventoryList
    {
        public static void Main()
        {
            ArrayList inv=new ArrayList();
            inv.Add(new Inventory("字符串1","字符串2"));
            inv.Add(new Inventory("字符串1","字符串2"));
            inv.Add(new Inventory("字符串1","字符串2"));
            foreach(Inventory i in inv)
            {
                string str1=i.toone;
                string str2=i.totwo;
                ......
            }
        }
    }
      

  2.   

    //参考代码
    ArrayList MainList = new ArrayList();ArrayList SubItem1 = new ArrayList();
    SubItem1.Add("item11");
    SubItem1.Add("item12");
    SubItem1.Add("item13");ArrayList SubItem2 = new ArrayList();
    SubItem2.Add("item21");
    SubItem2.Add("item22");
    SubItem2.Add("item23");MainList.Add(SubItem1);
    MainList.Add(SubItem2);foreach(ArrayList SubItem in MainList)
    {
       foreach(string ItemValue in SubItem)
      {
        MessageBox.Show(ItemValue)
      }
    }
      

  3.   

    简单的说ArrayList中的每个元素都是object,
    你要实现一个二维数组只要把ArrayList的每个元素改成一维数组就是了。
    一维数组:
    ArrayList arr1 = new ArrayList();
    arr1.Add(1);
    arr1.Add(2);
    arr1.Add(3);
    二维数组:
    ArrayList arr2 = new ArrayList();
    arr2.Add(new int[]{1,1});
    arr2.Add(new int[]{2,2});
             arr2.Add(new int[]{3,3});
      

  4.   

    rock1981(成功 = 心想 + 行动) 是正确答案