先声明三个数组//组1
        ArrayList _GP1 =new ArrayList();//组2
        ArrayList _GP2 = new ArrayList();//组3
        ArrayList _GP3 = new ArrayList();然后在Form1_Load对数据库进行提取数据,将这三个数组赋上值。不用循环的写法是:private void button1_Click(object sender, EventArgs e)
{
    if (ClientHandles.GetValue == 1)
            {
                if (_GP1.Count == 0)
                {
                }
                if (_GP1.Count == 1)
                {
                }
            }    if (ClientHandles.GetValue == 2)
            {
                if (_GP2.Count == 0)
                {
                }
                if (_GP2.Count == 1)
                {
                }
            }
    if (ClientHandles.GetValue == 3)
            {
                if (_GP3.Count == 0)
                {
                }
                if (_GP3.Count == 1)
                {
                }
            }
}
我现在想改成一个FOR循环,不会改,因为不知道变量i怎样融合到名字中 写一下伪代码吧直观点private void button1_Click(object sender, EventArgs e)
{
    if (ClientHandles.GetValue == i)
            {
                if (_GPi.Count == 0)//注意啦,这里的_GPi是伪代码,这个i值要和 if (ClientHandles.GetValue == i)的i值相同。
                {
                }
                if (_GPi.Count == 1)//注意啦,这里的_GPi是伪代码
                {
                }
            }
}
希望高手指点一下,最好能写出代码!!感激不尽!!!!!!

解决方案 »

  1.   

    string [] str1;
    string [] str2;
    string [] str3;
    for (int i =0;i <100;i i++)
    {
    str1[i]=i;
    str2[i]=i;
    str2[i]=i;
    }
    干嘛要用ArrayList 
      

  2.   

    基本上不知道你在说什么...为什么不用数组?ArrayList[] GP...最好用泛型List<List<T>> GP...
      

  3.   

    哎呀 最后一个写错了 重写下for(i =1; i<=3 ; i++)
    {
     if (ClientHandles.GetValue == i)
                {
                    if (_GPi.Count == 0)//注意啦,这里的_GPi是伪代码,这个i值要和 if (ClientHandles.GetValue == i)的i值相同。
                    {
                    }
                    if (_GPi.Count == 1)//注意啦,这里的_GPi是伪代码
                    {
                    }
                }
    }
      

  4.   

    我知道的比较少 项目里都是用这个东西提取数据的 
    比如load事件中写:            string mersql = "SELECT PointID,PointName From Points";
                myDatabase.ReturnIDAndName(connnectionString, mersql, ref _pointID1);            //遍历数组
                foreach (object abc in _pointID1)
                {
                    objProjects myObjProjects = (objProjects)abc;                _pointID2.Add(myObjProjects.GetPointID().ToString());
                    _pointID3.Add(myObjProjects.GetPointName().ToString());
                }这里的pointID1 pointID2 和pointID3 就是前面声明的ArrayList类型的
      

  5.   

    不知道把类型换成string数组行不行 我试试吧
      

  6.   

            private void button1_Click(object sender, EventArgs e)
            {
                for (int i = 1; i < 4; i++)
                {
                    if (i==1)
                    {
                        ClientHandles.GetValue == i;
                        if (_GPi.Count == 0)
                        {
                           //code
                        }
                        if (_GPi.Count == 1)
                        {
                            //code
                        }
                    }                if (i==2)
                    {
                        ClientHandles.GetValue == i ;
                        if (_GPi.Count == 0)
                        {
                            //code
                        }
                        if (_GPi.Count == 1)
                        {
                            //code
                        }
                    }
                    if (i == 3)
                    {
                        ClientHandles.GetValue == i 
                        if (_GPi.Count == 0)
                        {
                            //code
                        }
                        if (_GPi.Count == 1)
                        {
                            //code
                        }
                    }
                }
            }
    不晓得你要的是不是这种效果
      

  7.   


    ArrayList[] _GP = new ArrayList[3];
    for(int i=0;i<3;i++)
      _GP[i] = new ArrayList();private void button1_Click(object sender, EventArgs e)
    {
        int i = ClientHandles.GetValue - 1;
        if(i>=0 && i<3)
        {
            if (_GP[i].Count == 0
             {
            }
            else if (_GP[i].Count == 1)
             {
            }
        } 
    }
      

  8.   

    换个思路,当前的实现不了c# 没有能够完全替代 js 中 eval 函数的 东东http://topic.csdn.net/u/20091225/11/dbf3d928-c44d-483b-ae35-c96eb2b9a131.html
      

  9.   

    用泛型List <List <T>>
      

  10.   

    问题解决了,感谢ojlovecd(天行健) ,非常感谢!!