| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 639 人关注过本帖
标题:C#循环,急!
只看楼主 加入收藏
伤痕累累
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-11-9
结帖率:100%
收藏
 问题点数:0 回复次数:5 
C#循环,急!
有个C#程序,请问其中的几个循环condition1~condition14,是上一个循环先运行完了之后将所有数据传输给下一个循环。还是上一个循环先运行一遍将数据传输给下一个,然后 i++,再从新开始循环?
如果是前者,我想要达到后一种目的,该怎么办?



 //程序运行过程
        private void button3_Click(object sender, System.EventArgs e)
        {
            this.textBox84.Text = "";
            this.textBox85.Text = "";
            int i, i1, i2, i3, i4, i5, j, k = 0;
            int numofresult = 0;
            string s;
            string result = "输出结果为:" + "\r\n";
            DialogResult dr;
            for (j = 0; j < 50; j++)
            {
                if (ifwanttocheck[j])
                    k++;
            }
            if (k == 0)
            {
                MessageBox.Show("没有确定任何约束条件!", "警告", MessageBoxButtons.OKCancel);
                return;
            }
            if (k < 8)
            {
                dr = MessageBox.Show("约束条件太少,这将需要花费长时间等待输出结果!", "提示", MessageBoxButtons.OKCancel);
                if (dr == DialogResult.Cancel)
                    return;
            }
            for (i = 1; i <= 100; i++)
            {
                for (i1 = i + 1; i1 <= 100; i1++)
                {
                    for (i2 = i1 + 1; i2 <= 100; i2++)
                    {
                        for (i3 = i2 + 1; i3 <= 100; i3++)
                        {
                            for (i4 = i3 + 1; i4 <= 100; i4++)
                            {
                                for (i5 = i4 + 1; i5 <= 100; i5++)
                                {
                                    data[0] = i;
                                    data[1] = i1;
                                    data[2] = i2;
                                    data[3] = i3;
                                    data[4] = i4;
                                    data[5] = i5;
     //data[0]=2;
       //data[1]=4;
      //data[2]=6;
      //data[3]=8;
       //data[4]=10;
       //data[5]=12;
      if (ifwanttocheck[0])
      {
     condition1 mycondition1 = new condition1(data, dataofsplitting1, parameter1);
       if (!mycondition1.checkcondition1()) continue;
      }
    if (ifwanttocheck[1])
    {
condition2 mycondition2 = new condition2(data, parameter2);
     if (!mycondition2.checkcondition2()) continue;
//~略
if (ifwanttocheck[16])  
  {
   condition16 mycondition17 = new condition16(data, dataofsplitting17, parameter17);
   if (!mycondition17.checkcondition16()) continue;
   }
       s = i.ToString() + "-" + i1.ToString() + "-" + i2.ToString() + "-" + i3.ToString() + "-" + i4.ToString() + "-" + i5.ToString();
    numofresult++;
     result += s + "\r\n";
       s = "";
       }
     }
    }
    }
    }
      }
     this.textBox84.Text = result;
     this.textBox85.Text = numofresult.ToString();
        }

忘了加condition1了,其他的condition几乎一样。

namespace @@
{
    /// <summary>
    /// condition1 的摘要说明。
    /// </summary>
    public class condition1
    {
        int[]data=new int[6];
        int[][] dataofsplitting=new int[8][];
        int[] parameter=new int[4];
        ArrayList myarraylist=new ArrayList();
        ArrayList temp=new ArrayList();
        public condition1(int[]data,int[][]dataofsplitting,int[]parameter)
        {
            this.data=data;
            for(int i=0;i<8;i++)
                this.dataofsplitting[i]=new int[15];
            this.dataofsplitting=dataofsplitting;
            this.parameter=parameter;
        }
        public bool checkcondition1()
        {
            baseofcondition();
            if(!checkcondition11())
                return false;
            else if(!checkcondition12())
                return false;
            else if(!checkcondition13())
                return false;
            else
                return true;
        }
        private void baseofcondition()
        {
            int i,j,k;
            for(k=0;k<data.Length;k++)
            {
                for(i=0;i<8;i++)              
               {
                    for(j=0;j<dataofsplitting[i].Length;j++)
                    {
                        if(dataofsplitting[i][j]==data[k])
                        {
                            myarraylist.Add(i);
                            goto next;
                        }
                    }
                }
            next:;
            }
        }
        private bool checkcondition11()
        {
            int i,j;
            bool flag;
            int numofsplitting=1;
            for(i=0;i<myarraylist.Count-1;i++)
            {
                flag=false;
                for(j=i+1;j<myarraylist.Count;j++)
                {
                    if((int)myarraylist[j]==(int)myarraylist[i])
                    {
                        flag=true;
                        break;
                    }
                }
                if(!flag)
                {
                    numofsplitting++;
                    temp.Add(myarraylist[i]);
                }
            }
            temp.Add(myarraylist[myarraylist.Count-1]);
            if(parameter[0]<=numofsplitting&&numofsplitting<=parameter[1])
                return true;
            else
                return false;
        }
        private bool checkcondition12()
        {
            int i,j;
            int num;
            for(i=0;i<myarraylist.Count-2;i++)
            {
                num=1;
                for(j=i+1;j<myarraylist.Count;j++)
                {
                    if((int)myarraylist[j]==(int)myarraylist[i])
                        num++;
                }
                if(num>3)
                    return false;
            }
            return true;
        }
        private bool checkcondition13()
        {
            int i,j;
            int sumelement=0;
            for(i=0;i<temp.Count;i++)
            {
                for(j=0;j<dataofsplitting[(int)temp[i]].Length;j++)
                {
                    if(dataofsplitting[(int)temp[i]][j]!=0)
                        sumelement++;
                }
            }
            if(parameter[2]<=sumelement&&sumelement<=parameter[3])
                return true;
            else
                return false;
        }
    }
}





[ 本帖最后由 伤痕累累 于 2010-11-10 14:33 编辑 ]
搜索更多相关主题的帖子: 怎么办 void private 
2010-11-10 13:31
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
你可以在循环的位置设置一个断点,手动进入断点位置调试一下,看看程序是怎么运行的?!
2010-11-10 16:34
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
不是打击楼主 代码很乱 看着没头绪 请楼主按楼上的意见跟个断点试试 不行得话请把代码整理下在上传

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-11-11 08:20
伤痕累累
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-11-9
收藏
得分:0 
谢谢两位大大!我试一试看。
2010-11-11 10:38
amuqaz
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-4-21
收藏
得分:0 
是你本意
2010-11-11 10:50
loveyang
Rank: 2
等 级:论坛游民
帖 子:19
专家分:44
注 册:2010-11-12
收藏
得分:0 
很乱了啊
2010-11-15 17:29
快速回复:C#循环,急!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027672 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved