我需要用一个二维的动态数组,谁能给个实例参照一下,包括创建,添加记录,遍历数组,数组的生命周期是页面内,WinForm的
急用,谢谢大家了

解决方案 »

  1.   

    我用的是1.1,所以list用不了~~
      

  2.   

    (1)定义一个结构或类即可搞定。
    public class abc
    {
       public List<object> obj1 = new List<object>();
       public List<object> obj2 = new List<object>();
    }
    创建,添加记录,遍历数组应该自己可以搞定吧。
      

  3.   

    你还用VS2003呵。你可以用下面一维的改写成二维的。
            private void SubReDim(ref int[] List, bool IsIncrease)
            {
                //
                int iCount = 0;            try
                {
                    if (List == null || List.Length == 0)
                    {
                        int[] tmpList = new int[1];
                        List = tmpList;
                    }
                    else
                    {
                        if (IsIncrease)
                        {
                            iCount = List.Length;
                            int[] tmpList = new int[iCount + 1];
                            Array.Copy(List, tmpList, List.Length);
                            List = tmpList;
                        }
                        else
                        {
                            iCount = List.Length - 1;
                            int[] tmpList = new int[iCount + 1];
                            Array.Copy(List, tmpList, tmpList.Length);
                            List = tmpList;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.Trim(), "SubReDim Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
      

  4.   

    object [,] a = new object[m, n];
      

  5.   

        class DTClass
        {
            private string tabName;
            private string selString;        public DTClass(string name, string strSQL)
            {
                this.tabName = name;
                this.selString = strSQL;
            }        public string Name
            {
                get { return tabName; }
                set { tabName = value; }
            }        public string SelString
            {
                get { return selString; }
                set { selString = value; }
            }
        }    class DTClassIndexer //索引器, 用于对 DTClass 进行操作
        {
            private ArrayList arrDTClass;
            public DTClassIndexer()
            {
                arrDTClass = new ArrayList();
            }        //声明一个索引器
            public string this[string name]
            {
                get
                {
                    foreach (DTClass cs in arrDTClass)
                    {
                        if (cs.Name == name)
                        {
                            return cs.SelString;
                        }
                    }
                    return string.Empty;
                }
                set
                {
                    arrDTClass.Add(new DTClass(name, value)); //调用: arr["ss"]="asdfasfa";
                }
            }        public int Count() //返回长度
            {
                return arrDTClass.Count;
            }
        } static void Main()
    {
                ds["ss"] = "sss";
                Console.WriteLine(ds.Count());
                ds["sss"] = "sssss";
                Console.WriteLine(ds.Count());
    }