先声明三个数组//组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是伪代码
{
}
}
}
希望高手指点一下,最好能写出代码!!感激不尽!!!!!!
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是伪代码
{
}
}
}
希望高手指点一下,最好能写出代码!!感激不尽!!!!!!
string [] str2;
string [] str3;
for (int i =0;i <100;i i++)
{
str1[i]=i;
str2[i]=i;
str2[i]=i;
}
干嘛要用ArrayList
{
if (ClientHandles.GetValue == i)
{
if (_GPi.Count == 0)//注意啦,这里的_GPi是伪代码,这个i值要和 if (ClientHandles.GetValue == i)的i值相同。
{
}
if (_GPi.Count == 1)//注意啦,这里的_GPi是伪代码
{
}
}
}
比如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类型的
{
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
}
}
}
}
不晓得你要的是不是这种效果
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)
{
}
}
}